Readable large constants
Writing large constants such as limits, byte counts, or monetary values in source code.
JS Puzzles · Const
Numeric separators are underscores placed between digits in a number literal, such as 1_000_000. They improve readability while leaving the represented numeric value unchanged.
Numeric separators let you place underscores between digits in numeric literals. JavaScript ignores those underscores when evaluating the literal, so the value is unchanged; they are only syntactic sugar for readability.
number_literal_with_underscoresconst billion = 1_000_000_000;
const hex = 0xFF_FF;
console.log(billion === 1000000000); // true
console.log(hex === 65535); // trueUnderscores make digit groups easier to read while preserving the numeric value.
Writing large constants such as limits, byte counts, or monetary values in source code.
Representing hexadecimal, binary, or other supported numeric literals with grouped digits.
Numeric separators are underscores inserted between digits of a numeric literal, such as 1_000_000. The engine ignores them, so the literal has the same value as 1000000.
Follow-up: Can a separator be used outside a numeric literal? No; this feature is syntax for numeric literals, not a general number-formatting operation.
They improve the readability of large numeric literals without requiring string conversion or runtime formatting. For example, 1_000_000 clearly groups the digits while remaining a number.
Follow-up: How would you display locale-specific grouping instead? Use number-formatting APIs such as Intl.NumberFormat rather than source-level separators.
The separator is written as an underscore between digits, as in 1_000_000_000. It is part of the literal’s source syntax and is removed conceptually when the value is interpreted.
Follow-up: What value does 1_000_000_000 produce? It produces the same number as 1000000000.
Number literalsDecimal numbersHexadecimal numbersBinary numbersOctal numbers