JS: Number.prototype

By Xah Lee. Date: . Last updated: .

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

[see JS: Number Object]

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

Type

Type of Number.prototype is object.

[see JS: Value Types]

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

Parent

Parent of Number.prototype is Object.prototype.

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

[see JS: Prototype and Inheritance]

Purpose

Purpose of Number.prototype is to provide methods and properties useful for all number objects.

Properties

Convert to string:

Other:

Number.prototype.constructor

The value is Number.

[see JS: Number Object]

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

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

Number.prototype.valueOf

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

let 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

Number.prototype.toLocaleString

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

Reference

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

Number Topic

  1. JS: Format Number
  2. JS: String to Number
  3. JS: Number Object
  4. JS: Number Constructor
  5. JS: Number.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog