This section describes the broad range of numerical representation recognized in JavaScript.
Integers can be represented in base 10 ( decimal ), base 8 ( octal ), and base 16 ( hexadecimal ).
Octal integers are specified by a leading 0, and can contain digits 0 through 7. If a number has a leading 0 but contains the digits 8 and/or 9, it is a decimal number. A number that would otherwise be an octal number but contains the letter e or E generates an error.
0377 // An octal integer, equivalent to 255.
0378 // An integer, equivalent to 378.
Hexadecimal ( "hex" ) integers are specified by a leading 0x ( the X can be uppercase or lowercase ) and can contain digits 0 through 9 and letters A through F ( either uppercase or lowercase ). The letter e is a permissible digit in hex notation and does not signify an exponential number. The letters A through F are used to represent, as single digits, the numbers that are 10 through 15 in base 10. That is, 0xF is equivalent to 15, and 0x10 is equivalent to 16.
0Xff // A hexadecimal integer, equivalent to 255.
0x37CF // A hexadecimal integer, equivalent to 14287.
0x3e7 // A hexadecimal integer, equivalent to 999.
Octal and hexadecimal numbers can be negative, but cannot be fractional. A number that begins with a single 0 and contains a decimal point is a decimal floating-point number; if a number that begins with 0x or 00 contains a decimal point, anything to the right of the decimal point is ignored.
0.0001 //floating-point decimal
0x3.45e2
/* As hexadecimal numbers cannot have decimal parts,
this is equivalent to 3. */
00.0001
/* As octal numbers cannot have decimal parts,
this is equivalent to 0. */
Last, there are certain number values that are special:
- NaN, for not a number
- Positive Infinity
- Negative Infinity
- Positive 0
- Negative 0
Back to previous page