The Number constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the Number() function.
The JavaScript Number type is a value, like double in Java or C#. This means it can represent fractional values, but there are some limits to what it can store. A Number only keeps about 17 decimal places of precision; arithmetic is subject to . The largest value a Number can hold is about 1.8E308. Values higher than that are replaced with the special Number constant .
A number literal like 37 in JavaScript code is a floating-point value, not an integer. There is no separate integer type in common everyday use. (JavaScript now has a type, but it was not designed to replace Number for everyday uses. 37 is still a Number, not a BigInt.)
Number may also be expressed in literal forms like 0b101, 0o13, 0x0A. Learn more on numeric .
When used as a function, Number(value) converts a string or other value to the Number type. If the value can't be converted, it returns .
Copy to Clipboard
Copy to Clipboard
Creates a new Number value.
The smallest interval between two representable numbers.
The maximum safe integer in JavaScript (2^53 - 1).
The largest positive representable number.
The minimum safe integer in JavaScript (-(2^53 - 1)).
The smallest positive representable number—that is, the positive number closest to zero (without actually being zero).
Special "Not aNumber" value.
Special value representing negative infinity. Returned on overflow.
Special value representing infinity. Returned on overflow.
Allows the addition of properties to the Number object.
Determine whether the passed value is NaN.
Determine whether the passed value is a finite number.
Determine whether the passed value is an integer.
Determine whether the passed value is a safe integer (number between -(2^53 - 1) and 2^53 - 1).
This is the same as the global function.
This is the same as the global function.
Returns a string representing the number in exponential notation.
Returns a string representing the number in fixed-point notation.
Returns a string with a language sensitive representation of this number. Overrides the method.
Returns a string representing the number to a specified precision in fixed-point or exponential notation.
Returns a string representing the specified object in the specified radix ("base"). Overrides the method.
Returns the primitive value of the specified object. Overrides the method.
The following example uses the Number object's properties to assign values to several numeric variables:
Copy to Clipboard
The following example shows the minimum and maximum integer values that can be represented as Number object. (More details on this are described in the ECMAScript standard, chapter .)
Copy to Clipboard
When parsing data that has been serialized to JSON, integer values falling outside of this range can be expected to become corrupted when JSON parser coerces them to Number type.
A possible workaround is to use instead.
Larger numbers can be represented using the type.
The following example converts the object to a numerical value using Number as a function: