Skip to main content
Version: 1.7.0

Boolean()

The Boolean() constructor can create Boolean objects or return primitive values of type boolean.

Syntax

new Boolean(value)
Boolean(value)

Note: Boolean() can be called with or without new, but with different effects. See Return value.

Parameters

  • value
    • : The initial value of the Boolean object.

Return value

When Boolean() is called as a constructor (with new), it creates a Boolean object, which is not a primitive.

When Boolean() is called as a function (without new), it coerces the parameter to a boolean primitive.

Warning: You should rarely find yourself using Boolean as a constructor.

Description

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

Note: When the non-standard property document.all is used as an argument for this constructor, the result is a Boolean object with the value false. This property is legacy and non-standard and should not be used.