Example 1 — Call a prototype method
Parentheses help when the number is a literal.
JavaScript
console.log((2.5).toFixed(0));
console.log((255).toString(16)); 
Number.prototype holds methods shared by numbers, such as toFixed() and toString(). Number values use these methods through the prototype chain.
typeof Number.prototype.toFixed;
(3.14159).toFixed(2); | Name | Description |
|---|---|
— | Property on the Number constructor. |
The prototype object for Number instances.
Parentheses help when the number is a literal.
console.log((2.5).toFixed(0));
console.log((255).toString(16)); All numbers share toFixed.
console.log((1).toFixed === (2).toFixed); Static helpers live on Number, not the prototype.
console.log(Number.isNaN(NaN)); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful