These are only cosmetic changes in how we read the literals and numbers.
Numeric operators apply to numbers or literals allows developers to read them by separating a group of digits. _ or underscore symbol used as a separator.
if you are defining the number of One million as seen below
It is hard to read the number whether is one million or one lack thousand number.
The same number can be separated with _ as per your convenience in ES12.
Valid Numeric separators
Numeric separators are applied to number,float, binary, hex, octal and bigint literal types
Here is an example for floating literals
const floatNumber=10.23; // 10^10000
And also applied to fraction and exponent parts.
const exponentNumber=1e2_000; // 10^10000
Here is hexa,octal and binary literals example
const binaryNumber= 0b1110_0001_1010_0101; // binary number separation const hexaNumber = 0xB1_C8_D1; const octalNumber = 0o45_23_12;
bigint numbers separated with numeric operators.
let TwoTrillion = 2_000_000_000_000n;
The following are invalid separators which throws an error
const floating1 = 4.54_35_; // SyntaxError const invalid_separator = _1_000_000; // ReferenceError
- _ applies to any digits between the numbers only.
- Starting and Ending digits can not be applied underscore.
- numeric digits are not separated not immediate before n in bigint literal types.