string.toString

toString() ๋ฉ”์„œ๋“œ๋Š” ์ง€์ •๋œ ๊ฐ์ฒด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

const stringObj = new String('foo');
stringObj; // String {"foo"}
stringObj.toString(); // "foo"

Syntax

str.toString()

Return value

ํ˜ธ์ถœ๋œ ๊ฐ์ฒด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด

Description

String object๋Š” Object object์˜ toString() ๋ฉ”์„œ๋“œ๋ฅผ ์žฌ์ •์˜ํ•œ๋‹ค. ์ด๊ฒƒ์€ Object.prototype.toString() ์„ ์ƒ์†ํ•˜์ง€ ์•Š๋Š”๋‹ค. String object์˜ ๊ฒฝ์šฐ, toString() ๋ฉ”์„œ๋“œ๋Š” ํ•ด๋‹น object๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. (Stirng.prototype.valueOf()์™€ ๋™์ผ)

Examples

toString() ์‚ฌ์šฉ

const x = new String('Hello world');

x.toString(); // "Hello world"

Last updated

Was this helpful?