JavaScript Boolean prototype
Example
Make a new method for JavaScript booleans:
if (this.valueOf() == true) {
return "green";
} else {
return = "red";
}
};
Create a boolean, then call myColor():
let color = a.myColor();
Description
prototype allows you to add new properties and methods to booleans.
prototype is a property available with all JavaScript objects.
Syntax
Warning
You are not advised to change the prototype of an object that you do not control.
You should not change the prototype of built in JavaScript datatypes like:
- Numbers
- Strings
- Arrays
- Dates
- Booleans
- Function
- Objects
Only change the prototype of your own objects.
The prototype Property
The JavaScriptprototype property allows you to add new properties to objects:
Example
this.firstName = first;
this.lastName = last;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";
Browser Support
prototype is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |

