Easy Tutorial
❮ Prop Area Pathname Prop Del Datetime ❯

JavaScript Boolean prototype Constructor

JavaScript Boolean Object

Example

Creating a new method for the Boolean object:

Boolean.prototype.myColor = function() {
    if (this.valueOf() == true) {
        this.color = "green";
    } else {
        this.color = "red";
    }
}

Creating a Boolean object and adding the myColor method:

var a = new Boolean(1);
a.myColor();
var b = a.color;

b output result:


Definition and Usage

The prototype property allows you to add properties and methods to objects.

When constructing a prototype, all Boolean objects are by default given the properties or methods.

Note: Boolean.prototype does not refer to a Boolean value, but the Boolean() object does.

Note: Prototype is a global property, which is applicable to almost all JavaScript objects.


Browser Support

All major browsers support the prototype property.


Syntax


JavaScript Boolean Object

❮ Prop Area Pathname Prop Del Datetime ❯