JavaScript Boolean prototype
Example
Make a new method for JavaScript booleans:
Boolean.prototype.myColor = function() {
if (this.valueOf() == true) {
return "green";
} else {
return = "red";
}
};
Create a boolean, then call myColor():
let a = true;
a.myColor() // Returns green
Try it Yourself »
Definition and Usage
The prototype is a global constructor available for all JavaScript objects.
Boolean.prototype referres to the global Boolean() object.
The prototype constructor allows you to add new properties and methods to booleans.
When constructing a new property, ALL arrays will get the property and its value.
When constructing a new method, ALL arrays will get the method.
Browser Support
Boolean.prototype is fully supported in all browsers:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Boolean.prototype.name = value
Related Pages
JavaScript Tutorial: JavaScript Booleans
JavaScript Tutorial: JavaScript Data Types
JavaScript Tutorial: JavaScript Object Constructors

