JavaScript: Boolean.prototype

By Xah Lee. Date: .

Boolean.prototype is the value of the property key "prototype" of the Boolean object.

〔►see JavaScript: Boolean() Constructor Object

console.log( Boolean.hasOwnProperty ( "prototype" ) ); // true

Type of Boolean.prototype is object.

〔►see JavaScript: Data Types

// type of Boolean.prototype
console.log ( typeof Boolean.prototype === "object" ); // true
console.log ( Object.prototype.toString.call( Boolean.prototype ) === "[object Boolean]" ) // true

Parent of Boolean.prototype is Object.prototype.

// parent of Boolean.prototype
console.log ( Object.getPrototypeOf ( Boolean.prototype ) === Object.prototype ); // true

〔►see JavaScript: Prototype and Inheritance

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

Properties

  1. Boolean.prototype.constructor
  2. Boolean.prototype.valueOf
  3. Boolean.prototype.toString

Boolean.prototype.constructor

Value is Boolean.

console.log ( Boolean.prototype.constructor === Boolean ); // true

Boolean.prototype.valueOf

Boolean.prototype.toString () → converts the this binding to true or false.

console.log ( true.valueOf () === true ); // true
console.log ( false.valueOf () === false ); // true

Boolean.prototype.toString

Boolean.prototype.toString () → converts the this value to "true" or "false".

〔►see JavaScript: Keyword “this”

console.log ( true.toString () === "true" ); // true
console.log ( false.toString () === "false" ); // true

Reference

ECMAScript® 2016 Language Specification#sec-boolean.prototype

Boolean Topic

  1. JavaScript: What's True, False?
  2. JavaScript: Boolean() Constructor Object
  3. JavaScript: Boolean.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.