Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Boolean
  6. Boolean()

Boolean() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheBoolean() constructor createsBoolean objects. When called as a function, it returns primitive values of type Boolean.

Try it

const flag = new Boolean();console.log(typeof flag);// Expected output: objectconsole.log(flag === false);// Expected output: falseconst flag2 = Boolean();console.log(typeof flag2);// Expected output: booleanconsole.log(flag2 === false);// Expected output: true

Syntax

js
new Boolean(value)Boolean(value)

Note:Boolean() can be called with or withoutnew, but with different effects. SeeReturn value.

Parameters

value

The initial value of theBoolean object.

Return value

WhenBoolean() is called as a function (withoutnew), it returnsvaluecoerced to a boolean primitive.

WhenBoolean() is called as a constructor (withnew), it coercesvalue to a boolean primitive and returns a wrappingBoolean object, which isnot a primitive.

Warning:You should rarely find yourself usingBoolean as a constructor.

Description

The value passed as the first parameter isconverted to a boolean value. If the value is omitted or is0,-0,0n,null,false,NaN,undefined, or the empty string (""), then the object has an initial value offalse. All other values, including any object, an empty array ([]), or the string"false", create an object with an initial value oftrue.

Note:When the non-standard propertydocument.all is used as an argument for this constructor, the result is aBoolean object with the valuefalse. This property is legacy and non-standard and should not be used.

Examples

Creating Boolean objects with an initial value of false

js
const bZero = new Boolean(0);const bNull = new Boolean(null);const bEmptyString = new Boolean("");const bfalse = new Boolean(false);typeof bfalse; // "object"Boolean(bfalse); // true

Note how converting aBoolean object to a primitive withBoolean() always yieldstrue, even if the object holds a value offalse. You are therefore always advised to avoid constructingBoolean wrapper objects.

If you need to take the primitive value out from the wrapper object, instead of using theBoolean() function, use the object'svalueOf() method instead.

js
const bfalse = new Boolean(false);bfalse.valueOf(); // false

CreatingBoolean objects with an initial value oftrue

js
const btrue = new Boolean(true);const btrueString = new Boolean("true");const bfalseString = new Boolean("false");const bSuLin = new Boolean("Su Lin");const bArrayProto = new Boolean([]);const bObjProto = new Boolean({});

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-boolean-constructor

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp