Writing good code is important – writing easy-to-read code is the next level of skill. It’s not often that APIs are introduced whose seemingly only useful function makes code more readable, but I want to introduce you to JavaScript numeric delimiters: an API that allows developers to make underscores numbers more readable!

Consider the following number in your code:

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

Large numbers have always been difficult to engineer mentally for engineers, so using underscores to improve code readability is an overall win:

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

The only real rule with numeric separators is that a number cannot start or end with an underscore.

Numeric separators for JavaScript seem to give spec creators a feature. As an engineer, I take everything I get. You will never stop learning in the world of JavaScript!

  • Page Visibility API

    One event that has always been missing from a document is a signal when a user views a particular tab or another tab. When does a user turn off our site to see something else? When will they return?

  • 5 other HTML5 APIs you didn't know

    The HTML5 revolution has provided us with great JavaScript and HTML APIs. Some are APIs we knew we needed for years, others are high-end mobile and desktop helpers. Regardless of the strength or purpose of the API, anything that helps us do our job better is …

  • Fancy navigation with MooTools JavaScript

    Navigation menus are traditionally boring, right? Most of the time, the navigation menu consists of images with a corresponding mouse image. Where is the originality? I’ve created a great navigation menu that highlights navigation destinations and creates a chain effect. XHTML just a few simple …

  • Using MooTools 1.2 Drag, Drop, Sort, Save

LEAVE A REPLY

Please enter your comment!
Please enter your name here