JS: Number.prototype

By Xah Lee. Date: . Last updated: .

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

〔►see JS: Number() Constructor Object

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

Type of Number.prototype is object.

〔►see JS: Data Types

// type of Number.prototype
console.log ( typeof Number.prototype === "object" ); // true
console.log ( Object.prototype.toString.call( 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 JS: Prototype and Inheritance

The purpose of Number.prototype is object is to provides 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.toFixed

〔►see JS: Number.prototype.toFixed

Number.prototype.toPrecision

〔►see JS: Number.prototype.toPrecision

Number.prototype.toExponential

〔►see JS: Number.prototype.toExponential

Number.prototype.valueOf

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

Number.prototype.toString

〔►see JS: Number.prototype.toString

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: Number Object
  2. JS: Number Constructor
  3. JS: Number.prototype
Like what you read? Buy JavaScript in Depth