JS: Boolean.prototype

By Xah Lee. Date: . Last updated: .

What is boolean.prototype

Purpose

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

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);

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());
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");