JavaScript: Number.prototype

By Xah Lee. Date: . Last updated: .

Number.prototype is the value of the property key "prototype" of the Number object.

〔►see JavaScript: Number() Constructor Object

console.log( Number.hasOwnProperty ( "prototype" ) ); // true

Type of Number.prototype is object.

〔►see JavaScript: Data Types

// type of Number.prototype
console.log ( typeof Number.prototype === "object" ); // true
console.log ( Number.prototype ) === "[object Number]" ) // true

Parent of Number.prototype is Object.prototype.

// parent of Number.prototype
console.log ( Object.getPrototypeOf ( Number.prototype ) === Object.prototype ); // true

〔►see JavaScript: Prototype and Inheritance

The purpose of Number.prototype is object is to provides methods and properties useful for all number objects.


Convert to string:



The value is Number.

〔►see JavaScript: Number Object

console.log ( Number.prototype.constructor === Number ); // true

ECMAScript® 2016 Language Specification#sec-number.prototype.constructor


〔►see JavaScript: Number.prototype.toFixed


〔►see JavaScript: Number.prototype.toPrecision


〔►see JavaScript: Number.prototype.toExponential


Returns the number. (that is, a primitive value of number.)

var num = new Number(3);

console.log ( num === 3 ); // false
console.log ( num.valueOf ( ) === 3 ); // true

console.log ( typeof num === "object" ); // true
console.log ( typeof num.valueOf ( ) === "number" ); // true

ECMAScript® 2016 Language Specification#sec-number.prototype.valueof


〔►see JavaScript: Number.prototype.toString


Produces a String value that represents this Number value formatted according to the conventions of the host environment's current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

ECMAScript® 2016 Language Specification#sec-number.prototype.tolocalestring


ECMAScript® 2016 Language Specification#sec-properties-of-the-number-prototype-object

Number Topic

  1. JavaScript: Number Object
  2. JavaScript: Number Constructor
  3. JavaScript: Number.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.