Numeric Literal Formats
Version: ES2015 (octal, binary), ES2020 (BigInt)
// Number literals 123 // integer 1.23 // decimal 0xDEF // hexadecimal 0o077 // octal 0b101 // binary 1.23e+5 // exponential notation
BigInt literals are similar to Number literals except they include an
n suffix. BigInts also don’t support decimals or exponential syntax.
// BigInt literals 123n // integer 0xDEFn // hexadecimal 0o077n // octal 0b101n // binary
Note: You may also be familiar with an older octal style in which numbers starting with just a
0, rather than
0o, were seen as octal values. This format is considered deprecated, and in fact not allowed in strict mode, and should be avoided.
// The future 1_000_000 // numeric separators (= 1000000) 1.23m // BigDecimal (decimal version of BigInt) [email protected] // decorators (extended literals)
In fact, numeric separators are a stage 3 proposal and already available in most browsers today.