[i]Learn· Numbers and strings
Number object
The built-in Number object has properties for numerical constants, such as maximum value, not-a-number, and infinity. You cannot change the values of these properties and you use them as follows:
const biggestNum = Number.MAX_VALUE;
const smallestNum = Number.MIN_VALUE;
const infiniteNum = Number.POSITIVE_INFINITY;
const negInfiniteNum = Number.NEGATIVE_INFINITY;
const notANum = Number.NaN;
You always refer to a property of the predefined Number object as shown above, and not as a property of a Number object you create yourself.
The following table summarizes the Number object's properties.
| Property | Description |
|---|---|
Number.MAX_VALUE |
The largest positive representable number (1.7976931348623157e+308) |
Number.MIN_VALUE |
The smallest positive representable number (5e-324) |
Number.NaN |
Special "not a number" value |
Number.NEGATIVE_INFINITY |
Special negative infinite value; returned on overflow |
Number.POSITIVE_INFINITY |
Special positive infinite value; returned on overflow |
Number.EPSILON |
Difference between 1 and the smallest value greater than 1 that can be represented as a Number (2.220446049250313e-16) |
Number.MIN_SAFE_INTEGER |
Minimum safe integer in JavaScript (−2^53 + 1, or −9007199254740991) |
Number.MAX_SAFE_INTEGER |
Maximum safe integer in JavaScript (+2^53 − 1, or +9007199254740991) |
| Method | Description |
|---|---|
Number.parseFloat() |
Parses a string argument and returns a floating point number. Same as the global parseFloat() function. |
Number.parseInt() |
Parses a string argument and returns an integer of the specified radix or base. Same as the global parseInt() function. |
Number.isFinite() |
Determines whether the passed value is a finite number. |
Number.isInteger() |
Determines whether the passed value is an integer. |
Number.isNaN() |
Determines whether the passed value is NaN. More robust version of the original global isNaN(). |
Number.isSafeInteger() |
Determines whether the provided value is a number that is a safe integer. |
The Number prototype provides methods for retrieving information from Number objects in various formats. The following table summarizes the methods of Number.prototype.
| Method | Description |
|---|---|
toExponential() |
Returns a string representing the number in exponential notation. |
toFixed() |
Returns a string representing the number in fixed-point notation. |
toPrecision() |
Returns a string representing the number to a specified precision in fixed-point notation. |
example 1 of 1
[>_]Terminal
Output appears here when you press Run.
$ ▌