Large numeric literals are difficult for the human eye to parse quickly, especially when there are lots of repeating digits:
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:
// A decimal integer literal with its digits grouped per thousand:
// A decimal literal with its digits grouped per thousand:
// A binary integer literal with its bits grouped per octet:
// A binary integer literal with its bits grouped per nibble:
// A hexadecimal integer literal with its digits grouped by byte:
// A BigInt literal with its digits grouped per thousand:
They even work for octal integer literals (although I can’t think of an example where separators provide value for such literals):
// A numeric separator in an octal integer literal: 🤷♀️
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 #
- Safari: 自 13 版本开始支持