JS: Boolean.prototype

By Xah Lee. Date: . Last updated: .

What is Boolean.prototype

Boolean.prototype is the value of the property key "prototype" of the function Boolean. 〔see Boolean Object

console.assert((Object.hasOwn(Boolean, "prototype")) === true);

Type

Type of Boolean.prototype is Object .

console.assert(typeof Boolean.prototype === "object");

Boolean.prototype is a boolean object.

console.assert(Reflect.apply(Object.prototype.toString, Boolean.prototype, []) === "[object Boolean]");
console.assert(Reflect.apply(Boolean.prototype.valueOf, Boolean.prototype, []) === false);

Parent

Parent of Boolean.prototype is Object.prototype .

console.assert(Reflect.getPrototypeOf(Boolean.prototype) === Object.prototype);

Purpose

Purpose of Boolean.prototype is to hold methods valueOf and toString for converting values to true or false, or a string form.

Properties

Boolean.prototype.constructor

Value is Boolean.

console.assert(Boolean.prototype.constructor === Boolean);
console.assert(true.constructor === Boolean);
Boolean.prototype.valueOf()

Convert boolean object to primitive boolean.

console.assert((new Boolean(true)).valueOf() === true);
console.assert((new Boolean(false)).valueOf() === false);
Boolean.prototype.toString()

Convert boolean to string "true" or "false".

console.assert(true.toString() === "true");
console.assert(false.toString() === "false");

JavaScript. Boolean