8.5 Number

2010-04-13

Any number in Javascript is a double precision 64-bit floating point number. The specification mentions that there are exactly 18437736874454810627 different values (actually, 264 - 253 + 3). It can represent -9007199254740991 to 9007199254740991 (mentioned in 15.9.1.1).

There are five special numbers you might not expect:
- NaN: “Not a number”. This number represents “a number” that cannot be represented by the language. This is usually the result of an invalid computation (like “abc”/4). No NaN value is equal to NaN, not even the same variable. To check whether a number is in fact a NaN use the global function isNaN()
- Infinity (positive): Any “valid” number larger than the biggest number Ecmascript can represent. Adding 1 to the largest number produces infinity
- Infinity (negative)
- +0, is equal as 0 without a sign prefixed
- -0, is considered a different number from 0 or +0 (although in almost all math, they behave equally).

The exact syntax of number literals follows later.

Some methods and operators only work on integers or even positive integers. These will accept any number value but will first convert that value to their desired type using the (internal) ToInt32() and ToUINT32() functions.