The JavaScript number object enables you to represent a numeric value. It may be integer or floating-point. JavaScript number object follows IEEE standard to represent the floating-point numbers.
By the help of Number() constructor, you can create number object in JavaScript. For example:
If value can't be converted to number, it returns NaN(Not a Number) that can be checked by isNaN() method.
You can direct assign a number to a variable also. For example:
See this example:
Output:
Let's see the list of JavaScript number constants with description.
Constant | Description |
---|---|
MIN_VALUE | returns the largest minimum value. |
MAX_VALUE | returns the largest maximum value. |
POSITIVE_INFINITY | returns positive infinity, overflow value. |
NEGATIVE_INFINITY | returns negative infinity, overflow value. |
NaN | represents "Not a Number" value. |
Let's see the list of JavaScript number methods with description.
Methods | Description |
---|---|
toExponential(x) | displays exponential value. |
toFixed(x) | limits the number of digits after decimal value. |
toPrecision(x) | formats the number with given number of digits. |
toString() | converts number into string. |
valueOf() | coverts other type of value into number. |