JavaScript: Boolean.prototype
Boolean.prototype
is the value of the property key "prototype"
of the function Boolean
. [see Boolean Object]
console.log( Boolean.hasOwnProperty ( "prototype" ) );
Type
Type of Boolean.prototype
is Object
.
console.log( typeof Boolean.prototype === "object" );
Boolean.prototype
is a boolean object.
console.log( Reflect.apply ( Object.prototype.toString , Boolean.prototype , [] ) === "[object Boolean]" ); console.log( Object.prototype.valueOf.call ( Boolean.prototype ) ); // [Boolean: false] console.log( Reflect.apply ( Boolean.prototype.valueOf , Boolean.prototype , [] ) === false );
Parent
Parent of Boolean.prototype
is Object.prototype
.
console.log( 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
constructor
valueOf
toString
Boolean.prototype.constructor
-
Value is
Boolean
.
console.log( Boolean.prototype.constructor === Boolean ); console.log( true.constructor === Boolean );
val.valueOf()
-
Convert val to
true
orfalse
.
console.log( true.valueOf () === true ); console.log( false.valueOf () === false );
val.toString()
-
Convert val to
"true"
or"false"
.
console.log( true.toString () === "true" ); console.log( false.toString () === "false" );