“1_000_000 === 1000000” becomes TRUE – JavaScript

On recent web browsers,

“1_000_000 === 1000000”

becomes TRUE.

That is because it is a “Numeric Separator” specification that allows underscores in numeric value. (https://github.com/tc39/proposal-numeric-separator)

If you try to write value like 1 billion, you can improve the readability of numbers by separating them with underscores.

let a = 1000000000000;
let b = 1_000_000_000_000;
console.log(a===b); // TRUE

“Numeric Separator” supports not only integers but also various numerical formats.

// Decimal
let dec = 1_000_000.220_720;
// Binary
let bin = 0b1010_0001_1000_0101;
// Octal
let oct = 0o1234_5670;
// Hexadecimal
let hex = 0xA0_B0_C0;
// BigInt
let bint = 9_223_372_036_854_775_807n;

References

https://github.com/tc39/proposal-numeric-separator

https://v8.dev/features/numeric-separators

https://qiita.com/uhyo/items/4586dbc347d6985b44ef

Related Posts