JavaScript number separator


Writing good code is important-writing code that is easy for humans to read is the next level of skill. It’s not common to introduce APIs. Its seemingly only useful function is to make the code more readable, but let me introduce you to JavaScript number separators: a way for developers to use underscores to make numbers more readable API!

Consider the following numbers in your code:

// No commas for numbers in JavaScript
const oneHundredThousand = 100000;

For engineers, a large number of numbers have been difficult to parse, so using underscores to make the code more readable is a complete victory:

const oneMillion = 1_000_000; // 1000000
const decimals = 1_000_00.01_02_03 // 100000.010203

The only real rule for using number separators is that numbers cannot start or end with an underscore.

The number separator in JavaScript seems to be a feature provided to developers by the creator of the specification. As an engineer, I will do my best. You will never stop learning in the JavaScript world!

  • 39 Shirts – Leaving Mozilla

    In 2001, I just graduated from a high school in a small town and went to a university in the small town. I found myself in a quaint computer lab, where poor quality computers were equipped with two browsers: Internet Explorer and Mozilla. The place where I fell is this laboratory…

  • 5 awesome new Mozilla technologies you have never heard of

    My trip to the 2013 Mozilla Summit was incredible. I spent so much time focusing on my project that I overlooked all the great work done by the Mozillians. MozSummit is a perfect reminder of how smart my colleagues are and how much…


Leave a Reply

Your email address will not be published. Required fields are marked *