JavaScript: Number.prototype

By Xah Lee. Date: . Last updated: .

Number.prototype is the value of the property key "prototype" of the function Number. [see Number Object]

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

Type

Type of Number.prototype is Object .

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

Purpose

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

Properties

Convert to string:

Other:

constructor
Value is Number. [see Number Object]
console.log( Number.prototype.constructor === Number ); // true
valueOf
Return the number as primitive value.
console.log((new Number(3)).valueOf() === 3); // true
toLocaleString
Return a string that represents this number, formatted according to the conventions of the host environment's current locale. Implementation-dependent. May be the same as Number.prototype.toString.
ECMAScript® 2016 Language Specification#sec-number.prototype.tolocalestring

JavaScript Number

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Number

prototype