JS: Number Object
Number
is the value of the property key "Number"
of the global object.
[JS: the Global Object]
console.log( window["Number"] === Number ); // true
Type
Number
is a function.
[see JS: Value Types]
// type of Number console.log ( typeof Number === "function" ); // true
Parent
Parent of Number
is Function.prototype
. [see JS: Prototype and Inheritance]
// parent of Number console.log ( Object.getPrototypeOf ( Number ) === Function.prototype ); // true
Purpose
Purpose of Number
is:
- Implicitly called by JavaScript to work on number type values. example:
toString
. (by first converting a number primitive value to a number object then call toString.) - Has useful value properties (constants, such as
Number.MAX_VALUE
) and function properties. - Has the property key
"prototype"
that is the parent object of number object. It has properties such astoFixed
.
Number Primitive and Number Object
Numbers in JavaScript are primitive values. That is, the type of a number is number, not object.
[see JS: Value Types]
Number primitive include special literal expression NaN
and Infinity
.
[see JS: NaN]
[see JS: Infinity]
You can convert a primitive number type to a number object type by new Number(num)
.
Number Constructor
[see JS: Number Constructor]
Properties
Function Properties
- Number.parseInt
- Number.parseFloat
- Number.isFinite
- Number.isInteger
- Number.isNaN
- Number.isSafeInteger
Value Properties
- Number.prototype
Number.NaN
Number.NEGATIVE_INFINITY
Number.POSITIVE_INFINITY
Number.MIN_SAFE_INTEGER
Number.MAX_SAFE_INTEGER
Number.EPSILON
Number.MIN_VALUE
Number.MAX_VALUE
Number.NaN
Same as NaN
.
console.log ( Number.isNaN ( Number.NaN ) ); // true
ECMAScript® 2016 Language Specification#sec-number.nan
Number.NEGATIVE_INFINITY
Same as -Infinity
.
console.log ( Number.NEGATIVE_INFINITY === -Infinity ); // true
ECMAScript® 2016 Language Specification#sec-number.negative_infinity
Number.POSITIVE_INFINITY
Same as +Infinity
.
console.log ( Number.POSITIVE_INFINITY === Infinity ); // true
Number.MIN_SAFE_INTEGER
The value of Number.MIN_SAFE_INTEGER
is -9007199254740991 (-(2^53-1)).
It's 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).
It's 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
If you have a question, put $5 at patreon and message me.