Backbencher.dev

JS Daily 30 - Numeric Separator

Last updated on 20 Dec, 2020

What is the output of following code?

const num1 = 123456;
const num2 = 1_2_3_4_5_6;
console.log(num1 === num2);
----o----

The output is true.

Numeric separators are part of ES12. They are introduced to improve readability of numbers. The separators can be placed anywhere within the number. It does not affect the value in any way.

Numeric Separators work in the decimal place also. Eg: 123_56.786_95 is a valid number.

--- ○ ---
Joby Joseph
Web Architect