Numbers Enhanced
Last updated
Last updated
JavaScript implements all numbers in the . This basically means that JS incorporates all the numbers between -(253) -1 to 253 - 1. There is no specific type for numbers.
JavaScript is both able to represent floating-point numbers, as well as the symbolic value of Infinity
, -Infinity
, and NaN
(Not a Number). Basically, JS has in its library a vast supply of integers that are at the disposal of the developer.
You can use numberic literals for the following: decimal
, binary
, octal
, and hexadecimal
.
Note: decimal
literals can start with 0, followed by another decimal digit; however, if EVERY number following the 0 is LESS THAN 8, the number is parsed as an octal
number.
Binary
number syntax incorporates a leading 0, followed by the letter 'B' (upper or lower case - b
or B
). The appropriate numbers following should be either 0 or 1.
If the following numbers are not zero or one, a SyntaxError
is thrown.
Octal
number syntax begins with a 0, and is followed by digits ranging between 0 and 7.
Strict mode in ES2015 (or higher) forbids octal
syntax; rather, if desired, the developer must prefix an octal
number with a zero, followed by the letter 'O' (0o
).
Hexadecimal
numbers incorporate alpha-numberic digits to convey specific numeric values. The syntax uses a 0, followed by the letter 'X' (upper or lower case - x
or X
). The range of the digits must be the following: 0123456789ABCDEF; if it is outside this range, a SyntaxError
is thrown.