English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Boolean prototype property

 JavaScript Boolean Object

prototypeProperties allow you to add properties and methods to the Boolean() object.

Note:prototype is a global property that is available for almost all objects (numbers, arrays, strings, dates, and so on).

Syntax:

Boolean.prototype.name = value

Create a new boolean method to change the paragraph's background:

Boolean.prototype.isEven = function() {
if (this.valueOf() == true) {
return "lightgreen";
} else {
return "red";
}
};

Then create a boolean value and call the isEven() method:

function myFunc() {
   var a = true;
   document.getElementById('result').style.background = a.isEven();
}

Test and see‹/›

Browser Compatibility

All browsers fully support the prototype property:

Properties
prototypeYesYesYesYesYes

 JavaScript Boolean Object