Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Boolean 객체는 불리언 값을 감싸고 있는 객체입니다.
첫 번째 매개변수로서 전달한 값은 필요한 경우 불리언 값으로 변환됩니다. 값이 없거나 0, -0, null, false, NaN, undefined, 빈 문자열 ("")이라면 객체의 초기값은 false가 됩니다. 문자열 "false"를 포함한 그 외 모든 다른 값은 초기값을 true로 설정합니다.
Boolean 객체의 true와 false 값을 원시 Boolean 값 true, false와 혼동해선 안됩니다.
값이 undefined, null이 아닌 모든 객체는 조건문에서 true로 계산됩니다. 이는 값이 false인 Boolean 객체도 포함합니다. 즉 아래 if 문의 조건은 참입니다.
그러나 원시 Boolean 값에는 적용되지 않습니다. 따라서 아래 if 문의 조건은 거짓입니다.
불리언이 아닌 값을 변환할 때 Boolean 객체를 사용해선 안됩니다. 대신 Boolean 함수를 사용하세요.
값이 false인 Boolean 객체를 포함한 어떠한 객체를 Boolean 객체의 초기값으로 넘겨주더라도 새로운 Boolean 객체는 true를 가집니다.
Boolean 원시 값의 자리에서 Boolean 객체를 이용해선 안됩니다.
Boolean 객체를 생성합니다.
객체의 값에 따라 문자열 "true" 또는 "false"를 반환합니다. Object.prototype.toString() 메서드를 재정의합니다.
Boolean.prototype.valueOf()Boolean 객체의 원시값을 반환합니다. Object.prototype.valueOf() 메서드를 재정의합니다.
| ECMAScript® 2027 Language Specification # sec-boolean-objects |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2023년 8월 8일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.