JSTotD: Why use numeric separators?

Re: Numeric Literal Formats

Why would I write a number 1000000 like this 1_000_000 ?
What is the meaning of separator here?

They serve no functional purpose. Instead they’re useful strictly for readability. When seeing 1000000 in code, you might not realize right away that its a million. You might have to count zeros. Its worse with a billion: 1000000000. With separators, you can more easily tell by having separators work like commas in written numbers, separating by thousand: 1_000_000_000. That’s more easily identifiable as a billion. The proposal has a few more other examples each doing something similar, separating numbers in certain ways to make them more readable.

1 Like

True. That’s a good idea. With thousands of line of code scrolling down keeping it readable is a challenge indeed.

2 Likes