ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

20.3 Boolean Objects

20.3.1 The Boolean Constructor

The Boolean constructor:

  • is %Boolean%.
  • is the initial value of the "Boolean" property of the global object.
  • creates and initializes a new Boolean object when called as a constructor.
  • performs a type conversion when called as a function rather than as a constructor.
  • may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Boolean behaviour must include a super call to the Boolean constructor to create and initialize the subclass instance with a [[BooleanData]] internal slot.

20.3.1.1 Boolean ( value )

This function performs the following steps when called:

  1. Let b be ToBoolean(value).
  2. If NewTarget is undefined, return b.
  3. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »).
  4. Set O.[[BooleanData]] to b.
  5. Return O.

20.3.2 Properties of the Boolean Constructor

The Boolean constructor:

  • has a [[Prototype]] internal slot whose value is %Function.prototype%.
  • has the following properties:

20.3.2.1 Boolean.prototype

The initial value of Boolean.prototype is the Boolean prototype object.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.3.3 Properties of the Boolean Prototype Object

The Boolean prototype object:

  • is %Boolean.prototype%.
  • is an ordinary object.
  • is itself a Boolean object; it has a [[BooleanData]] internal slot with the value false.
  • has a [[Prototype]] internal slot whose value is %Object.prototype%.

20.3.3.1 Boolean.prototype.constructor

The initial value of Boolean.prototype.constructor is %Boolean%.

20.3.3.2 Boolean.prototype.toString ( )

This method performs the following steps when called:

  1. Let b be ? ThisBooleanValue(this value).
  2. If b is true, return "true"; else return "false".

20.3.3.3 Boolean.prototype.valueOf ( )

This method performs the following steps when called:

  1. Return ? ThisBooleanValue(this value).

20.3.3.3.1 ThisBooleanValue ( value )

The abstract operation ThisBooleanValue takes argument value (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. If value is a Boolean, return value.
  2. If value is an Object and value has a [[BooleanData]] internal slot, then
    1. Let b be value.[[BooleanData]].
    2. Assert: b is a Boolean.
    3. Return b.
  3. Throw a TypeError exception.

20.3.4 Properties of Boolean Instances

Boolean instances are ordinary objects that inherit properties from the Boolean prototype object. Boolean instances have a [[BooleanData]] internal slot. The [[BooleanData]] internal slot is the Boolean value represented by this Boolean object.