This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Boolean.prototype.toString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2015๋…„ 7์›”โฉ.

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

์‹œ๋„ํ•ด ๋ณด๊ธฐ

const flag1 = new Boolean(true);

console.log(flag1.toString());
// Expected output: "true"

const flag2 = new Boolean(1);

console.log(flag2.toString());
// Expected output: "true"

๊ตฌ๋ฌธ

js
bool.toString();

๋ฐ˜ํ™˜ ๊ฐ’

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

์„ค๋ช…

Boolean ๊ฐ์ฒด๋Š” Object.prototype.toString() ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์†๋ฐ›์ง€ ์•Š๊ณ  ์žฌ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. Boolean ๊ฐ์ฒด์—์„œ toString() ๋ฉ”์„œ๋“œ๋Š” ๊ฐ์ฒด์˜ ๋ฌธ์ž์—ด ํ‘œํ˜„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

JavaScript๋Š” Boolean์„ ๋ฌธ์ž์—ด๋กœ ํ‘œํ˜„ํ•ด์•ผ ํ•  ๋•Œ๋‚˜ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ์— ์‚ฌ์šฉํ•  ๋•Œ toString()์„ ์ž๋™์œผ๋กœ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

toString()์€ ๋ถˆ๋ฆฌ์–ธ ๊ฐ์ฒด์˜ ๊ฐ’์— ๋”ฐ๋ผ ๋ฌธ์ž์—ด "true" ๋˜๋Š” "false"๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

toString() ์‚ฌ์šฉํ•˜๊ธฐ

js
var flag = new Boolean(true);
flag.toString(); // false

๋ช…์„ธ

Specification
ECMAScriptยฎ 2026 Language Specification
# sec-boolean.prototype.tostring

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ