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]

console.log ( typeof Number.prototype === "object" ); // true

Number.prototype is actually a number. It has a value of 0.

console.log (
Reflect.apply ( Object.prototype.toString ,  Number.prototype , [] ) === "[object Number]"
); // true

console.log (
Reflect.apply ( Number.prototype.valueOf , Number.prototype, [] ) === 0
); // true

Parent

Parent of Number.prototype is Object.prototype.

console.log ( Reflect.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

JS Number

  1. Format Number
  2. String to Number
  3. Number Object
  4. Number.prototype
Like it? Help me by telling your friends. Or, 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 Object Ref
  5. DOM Scripting
  6. SVG
  7. Blog