What are numeric separators?
When working with large numbers it can be hard to read them out, try to read this value for example:
const value = 100000000;
Numeric separators are a JavaScript feature that allows you to use underscore as a separator in numeric literals, for example, you can write 10000
as 10_000
. The feature works in recent versions of modern browsers as well as Node.js.
When we apply this to the top example we can easily read out the value:
const value = 100_000_000;
The numeric separator also works on octal, hex, and binary numbers:
const octalValue = 0o32_12;
const hexValue = 0xff_55_00;
const binaryValue = 0b1010_1011_1111;
Now let's keep those numbers easy to read!