Number
The Number global object converts values to numbers when it’s called as a function, and holds the constants and methods for working with them. The primitive itself is the number type, and Number.prototype supplies the methods that every number value can call:
> Number("42.5")
42.5
> Number.isInteger(42.5)
false
> (42.5).toFixed(2)
'42.50'
Number is an ECMAScript built-in. Its static methods test and parse values without coercing them in surprising ways, and its instance methods turn numbers into formatted strings.
Syntax
The Number function takes one optional value to convert:
Number([<value>])
new Number([<value>])
| Parameter | Description |
|---|---|
value |
An optional value of any type to convert. It defaults to 0 when omitted |
Without the new keyword, the call returns a number primitive, or NaN when the value can’t be converted. A symbol can’t be converted at all, so Number(Symbol()) throws a TypeError. With new, it returns a Number wrapper object, which is rarely useful because it isn’t a primitive.
Key Static Methods and Properties
| Member | Kind | Description |
|---|---|---|
Number.isNaN() |
Static method | Returns true only when the argument is the NaN value, without converting it first |
Number.isFinite() |
Static method | Returns true for numbers that aren’t NaN, Infinity, or -Infinity |
Number.isInteger() |
Static method | Returns true for numbers with no fractional part |
Number.isSafeInteger() |
Static method | Returns true for integers from -(2 ** 53 - 1) to 2 ** 53 - 1, where no other integer rounds to the same value |
Number.parseFloat() |
Static method | Parses a leading decimal number from a string, the same function as the global parseFloat() |
Number.parseInt() |
Static method | Parses an integer from a string in a given radix, the same function as the global parseInt() |
Number.MAX_SAFE_INTEGER |
Static property | Holds the largest safe integer, 2 ** 53 - 1 |
Number.MIN_SAFE_INTEGER |
Static property | Holds the smallest safe integer, -(2 ** 53 - 1) |
Number.EPSILON |
Static property | Holds the gap between 1 and the next representable number |
Number.MAX_VALUE |
Static property | Holds the largest representable positive number |
Number.MIN_VALUE |
Static property | Holds the smallest positive number greater than zero |
Number.NaN |
Static property | Holds the NaN value |
Number.POSITIVE_INFINITY |
Static property | Holds Infinity |
Number.NEGATIVE_INFINITY |
Static property | Holds -Infinity |
Key Instance Methods and Properties
| Member | Kind | Description |
|---|---|---|
.toFixed() |
Instance method | Returns a string with a fixed number of digits after the decimal point |
.toPrecision() |
Instance method | Returns a string with a given number of significant digits |
.toExponential() |
Instance method | Returns a string in exponential notation |
.toString() |
Instance method | Returns a string in the given radix, from 2 to 36, defaulting to 10 |
.toLocaleString() |
Instance method | Returns a locale-aware string, using Intl formatting options |
.valueOf() |
Instance method | Returns the primitive number that a Number object holds |
Examples
A quantity field in an order form arrives as a string. Calling Number() converts the whole string or gives NaN, while Number.parseFloat() reads only the leading number:
> Number("3 boxes")
NaN
> Number.parseFloat("3 boxes")
3
> Number.isInteger(Number("2.5"))
false
An ID from an external API can exceed the safe integer range, where neighboring integers collapse into one value. Number.isSafeInteger() flags those before they cause mismatches:
> Number.isSafeInteger(9007199254740991)
true
> Number.isSafeInteger(9007199254740993)
false
A checkout page shows prices with two decimals, and a color picker needs a hex channel value. The formatting methods return strings for both:
> const total = 1234.5;
undefined
> total.toFixed(2)
'1234.50'
> total.toLocaleString("en-US", { style: "currency", currency: "USD" })
'$1,234.50'
> (255).toString(16)
'ff'
Pick a number, drag the digits slider, and choose a radix to see the string each formatting method returns, including the 1.005 case where .toFixed(2) rounds down:
Common Gotchas
The global isNaN() function converts its argument first, so it reports true for strings that aren’t numbers. Number.isNaN() checks for the NaN value itself:
> isNaN("hello")
true
> Number.isNaN("hello")
false
The .toFixed() method rounds the stored binary value, not the decimal literal, so some halves round down:
> (1.005).toFixed(2)
'1.00'
A Number object is truthy even when it holds 0, because every object is truthy:
> const stock = new Number(0);
undefined
> stock ? "in stock" : "sold out"
'in stock'
Related Resources
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 7, 2026