Why 1000000 and 1_000_000 both are same?

const a = 1000000;
const b = 1_000_000;

now if i checked

console.log(1000000 === 1_000_000);

and it’s return true

Why 1000000 and 1_000_000 both are same in javascript?

6 thoughts on “Why 1000000 and 1_000_000 both are same?”

  1. It is a feature for readability, so you can define a large number without having to scroll your eyes back and forth.

    It exists for other languages too like C#.

    Reply
  2. Because the underscores are optional and purely for legibility.

    Be careful using them in native JavaScript though, since they’re not supported in all browsers: CanIUse

    Reply

Leave a Comment