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.
In this article
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: trueSyntax
new Boolean(value)Boolean(value)Note:Boolean() can be called with or withoutnew, but with different effects. SeeReturn value.
Parameters
valueThe initial value of the
Booleanobject.
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
const bZero = new Boolean(0);const bNull = new Boolean(null);const bEmptyString = new Boolean("");const bfalse = new Boolean(false);typeof bfalse; // "object"Boolean(bfalse); // trueNote 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.
const bfalse = new Boolean(false);bfalse.valueOf(); // falseCreatingBoolean objects with an initial value oftrue
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> |