Large numeric literals are difficult for the human eye to parse quickly, especially when there are lots of repeating digits:
1000000000000
1019436871.42
To improve readability, a new JavaScript language feature enables underscores as separators in numeric literals. So, the above can now be rewritten to group the digits per thousand, for example:
1_000_000_000_000
1_019_436_871.42
Now it’s easier to tell that the first number is a trillion, and the second number is in the order of 1 billion.
Numeric separators help improve readability for all kinds of numeric literals:
1_000_000_000_000
1_000_000.220_720
0b01010110_00111000
0b0101_0110_0011_1000
0x40_76_38_6A_73
4_642_473_943_484_686_707n
They even work for octal integer literals (although I can’t think of an example where separators provide value for such literals):
0o123_456
Note that JavaScript also has a legacy syntax for octal literals without the explicit 0o
prefix. For example, 017 === 0o17
. This syntax is not supported in strict mode or within modules, and it should not be used in modern code. Accordingly, numeric separators are not supported for these literals. Use 0o17
-style literals instead.
Support for numeric separators #