# JavaScript Reference: Number

> Learn how JavaScript Number values work, what the static constants and methods mean, how formatting methods behave, and when to use BigInt.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-03-26 | Updated: 2026-07-18 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-number/

This article explains how to work with JavaScript `Number` values and the built-in `Number` object.

JavaScript Numbers use the IEEE 754 binary64 format. The same type represents integers, fractions, `Infinity`, `-Infinity`, and `NaN`.

The exact rules are defined in the [ECMAScript Number specification](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number-objects).

## Create a Number value

The usual way is a number literal:

```js
const age = 36
typeof age // 'number'
```

You can call `Number()` to convert another value:

```js
Number('36') // 36
Number('') // 0
Number(true) // 1
Number('hello') // NaN
```

`Number()` follows JavaScript's numeric conversion rules, which can sometimes be surprising. Validate input instead of assuming every conversion succeeded.

## Avoid `new Number()`

Adding `new` creates a wrapper object, not a Number primitive:

```js
const age = new Number(36)

typeof age // 'object'
age.valueOf() // 36
```

Wrapper objects behave differently in comparisons and conditionals:

```js
new Number(0) === 0 // false
Boolean(new Number(0)) // true
```

Use Number primitives unless you have a very unusual reason to create a wrapper object.

## Static properties

The `Number` constructor provides these constants:

- `Number.EPSILON` is the difference between 1 and the smallest Number greater than 1
- `Number.MAX_SAFE_INTEGER` is `2 ** 53 - 1`, the largest safe integer
- `Number.MIN_SAFE_INTEGER` is `-(2 ** 53 - 1)`, the smallest safe integer
- `Number.MAX_VALUE` is the largest positive finite Number
- `Number.MIN_VALUE` is the smallest positive nonzero Number, not the most negative Number
- `Number.NaN` is the special not-a-number value
- `Number.NEGATIVE_INFINITY` is negative infinity
- `Number.POSITIVE_INFINITY` is positive infinity

Their values are:

```js
Number.EPSILON // 2.220446049250313e-16
Number.MAX_SAFE_INTEGER // 9007199254740991
Number.MIN_SAFE_INTEGER // -9007199254740991
Number.MAX_VALUE // 1.7976931348623157e+308
Number.MIN_VALUE // 5e-324
Number.NaN // NaN
Number.NEGATIVE_INFINITY // -Infinity
Number.POSITIVE_INFINITY // Infinity
```

`Number.EPSILON` is not the spacing between every pair of Numbers. Floating-point spacing grows with the magnitude of the values.

## Static methods

These methods test or parse a value:

- [`Number.isNaN(value)`](https://flaviocopes.com/javascript-number-isnan/) returns `true` only when `value` is the Number value `NaN`; it does not coerce
- [`Number.isFinite(value)`](https://flaviocopes.com/javascript-number-isfinite/) returns `true` only for a finite Number; it does not coerce
- [`Number.isInteger(value)`](https://flaviocopes.com/javascript-number-isinteger/) returns `true` when the value is a Number with no fractional part
- [`Number.isSafeInteger(value)`](https://flaviocopes.com/javascript-number-issafeinteger/) returns `true` when the value is an exactly represented integer in the safe range
- [`Number.parseFloat(value)`](https://flaviocopes.com/javascript-number-parsefloat/) parses a decimal Number from the beginning of a string
- [`Number.parseInt(value, radix)`](https://flaviocopes.com/javascript-number-parseint/) parses an integer from the beginning of a string using the requested base

Examples:

```js
Number.isNaN(NaN) // true
Number.isNaN('hello') // false
Number.isFinite(10) // true
Number.isFinite('10') // false
Number.isInteger(10.0) // true
Number.isSafeInteger(9007199254740991) // true
Number.parseFloat('12.5px') // 12.5
Number.parseInt('101', 2) // 5
```

`Number.parseFloat()` and `Number.parseInt()` can return `NaN`, so check the result when parsing untrusted input.

## What is a safe integer?

A safe integer is an integer that is exactly represented and does not share its Number representation with another integer.

The safe range is:

```text
-(2 ** 53 - 1) through 2 ** 53 - 1
```

Outside that range, some integers are exactly representable and others are not. You cannot assume that consecutive mathematical integers remain distinguishable:

```js
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
// true
```

Use `Number.isSafeInteger()` before relying on exact integer behavior.

## Use BigInt for larger integers

When you need arbitrary-size integer arithmetic, use `BigInt`:

```js
const count = 9007199254740993n
const next = count + 1n

next // 9007199254740994n
```

`BigInt` is a separate primitive type. You cannot mix a BigInt and a Number directly in arithmetic:

```js
1n + 1 // TypeError
```

Convert deliberately when needed, and remember that converting a large BigInt to Number can lose precision.

## Number prototype methods

Number primitives can use the methods on `Number.prototype`. JavaScript temporarily boxes the primitive for the method call, so you do not need `new Number()`.

```js
const price = 12.5

price.toFixed(2) // '12.50'
```

The main methods are:

- [`.toExponential()`](https://flaviocopes.com/javascript-number-toexponential/) returns a string in exponential notation
- [`.toFixed()`](https://flaviocopes.com/javascript-number-tofixed/) returns a fixed-point string with the requested number of fractional digits
- [`.toLocaleString()`](https://flaviocopes.com/javascript-number-tolocalestring/) formats the value using locale-sensitive conventions
- [`.toPrecision()`](https://flaviocopes.com/javascript-number-toprecision/) returns a string with the requested number of significant digits
- [`.toString()`](https://flaviocopes.com/javascript-number-tostring/) returns a string, optionally using a radix from 2 through 36
- [`.valueOf()`](https://flaviocopes.com/javascript-number-valueof/) returns the Number primitive stored by a wrapper object

Examples:

```js
const value = 1234.567

value.toExponential(2) // '1.23e+3'
value.toFixed(2) // '1234.57'
value.toPrecision(4) // '1235'
value.toString(16) // '4d2.9126e978d5'
value.toLocaleString('it-IT') // output depends on the runtime locale data
```

All formatting methods return strings. They do not change the original Number.
