Number
is a primitive wrapper object used to represent and manipulate numbers like 37
or -9.25
.
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 double-precision 64-bit binary format IEEE 754 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 rounding. The largest value a Number
can hold is about 1.8E308. Values higher than that are replaced with the special Number
constant Infinity
.
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 BigInt
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 lexical grammar here.