JavaScript: Number Object

By Xah Lee. Date: . Last updated: .

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

console.log( window["Number"] === Number ); // true

Number is a function.

〔►see JavaScript: Data Types

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

The parent of Number is Function.prototype. 〔►see JavaScript: Prototype and Inheritance

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

The purpose of Number is:

  1. Implicitly called by JavaScript to work on number type values. e.g. toString. (by first converting a number primitive value to a number object then call toString.)
  2. Has useful value properties (constants, such as Number.MAX_VALUE) and function properties.
  3. Has the property key "prototype" that is the parent object of number object. It has properties such as toFixed.

Number Primitive and Number Object

Numbers in JavaScript are primitive values. That is, the type of a number is number, not object.

〔►see JavaScript: Data Types

Number primitive include special literal expression NaN and Infinity.

〔►see JavaScript: NaN

〔►see JavaScript: Infinity

You can convert a primitive number type to a number object type by new Number(num).

〔►see JavaScript: Number Constructor

Number Constructor

〔►see JavaScript: Number Constructor

Properties

Function Properties

  1. Number.parseInt (ES2015)
  2. Number.parseFloat (ES2015)
  1. Number.isFinite (ES2015)
  2. Number.isInteger (ES2015)
  3. Number.isNaN (ES2015)
  4. Number.isSafeInteger (ES2015)

Value Properties

  1. Number.prototype
  1. Number.NaN
  2. Number.NEGATIVE_INFINITY
  3. Number.POSITIVE_INFINITY
  1. Number.MIN_SAFE_INTEGER (ES2015)
  2. Number.MAX_SAFE_INTEGER (ES2015)
  1. Number.EPSILON (ES2015)
  2. Number.MIN_VALUE
  3. Number.MAX_VALUE

Number.prototype

〔►see JavaScript: Number.prototype

Number.parseInt ( string, radix )

〔►see JavaScript: Number.parseInt

Number.parseFloat ( string )

〔►see JavaScript: Number.parseFloat

Number.isFinite ( number )

〔►see JavaScript: Number.isFinite

Number.isInteger ( number )

〔►see JavaScript: Number.isInteger

Number.isNaN ( number )

〔►see JavaScript: Number.isNaN

Number.isSafeInteger ( number )

〔►see JavaScript: Number.isSafeInteger

Number.NaN

The value of Number.NaN is NaN.

console.log ( Number.isNaN ( Number.NaN ) ); // true

ECMAScript® 2016 Language Specification#sec-number.nan

Number.NEGATIVE_INFINITY

The value of Number.NEGATIVE_INFINITY is -Infinity.

console.log ( Number.NEGATIVE_INFINITY === -Infinity ); // true

ECMAScript® 2016 Language Specification#sec-number.negative_infinity

Number.POSITIVE_INFINITY

The value of Number.POSITIVE_INFINITY is +Infinity.

console.log ( Number.POSITIVE_INFINITY === Infinity ); // true

Number.MIN_SAFE_INTEGER

The value of Number.MIN_SAFE_INTEGER is -9007199254740991 (-(2^53-1)).

The value of Number.MIN_SAFE_INTEGER is the smallest integer n such that n and n - 1 are both exactly representable as a Number value.

console.log(
    Number.MIN_SAFE_INTEGER
); // -9007199254740991

ECMAScript® 2016 Language Specification#sec-number.min_safe_integer

Number.MAX_SAFE_INTEGER

The value of Number.MAX_SAFE_INTEGER is 9007199254740991. That is, (2^53 - 1).

The value of Number.MAX_SAFE_INTEGER is the largest integer n such that n and n + 1 are both exactly representable as a Number value.

console.log(
    Number.MAX_SAFE_INTEGER
); // 9007199254740991

ECMAScript® 2016 Language Specification#sec-number.max_safe_integer

Number.EPSILON

The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1 that is representable as a Number value, which is approximately 2.2204460492503130808472633361816 x 10^(-16).

console.log(
    Number.EPSILON
); // 2.220446049250313e-16

ECMAScript® 2016 Language Specification#sec-number.epsilon

Number.MIN_VALUE

The value of Number.MIN_VALUE is the smallest positive value of the Number type, which is approximately 5 × 10^(-324).

In the IEEE 754-2008 double precision binary representation, the smallest possible value is a denormalized number. If an implementation does not support denormalized values, the value of Number.MIN_VALUE must be the smallest non-zero positive value that can actually be represented by the implementation.

console.log(
    Number.MIN_VALUE
); // 5e-324

// that's 5 * 10^(-324)

ECMAScript® 2016 Language Specification#sec-number.min_value

Number.MAX_VALUE

The value of Number.MAX_VALUE is the largest positive finite value of the Number type, which is approximately 1.7976931348623157 × 10^308.

console.log (
    Number.MAX_VALUE
 ); // 1.7976931348623157e+308

ECMAScript® 2016 Language Specification#sec-number.max_value

Reference

ECMAScript® 2016 Language Specification#sec-number-objects

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.