DEV Community

Mohana Naga Venkat Sayempu
Mohana Naga Venkat Sayempu

Posted on

5 1

JavaScript Numeric Separators

Have you ever feel the pain of your eye when you try to read large numeric literals, If not try to read the following values.

const num = 1000000000000;

There is a feature in javascript that enables underscore as a separator in numeric literals to improve readability.

Example:

const num = 1_000_000_000_000;

You can also use this for binary, octal, and hex numbers.

const n1 = 0b1010_0101_1001; // binary
const n2 = 0o2_3_5_7; // octal
const n3 = 0xA_B_C_D_E; // hex

There is good support for this feature in recent versions of browsers. To check for the support visit https://caniuse.com/#feat=mdn-javascript_grammar_numeric_separators.

I hope this adds something to your knowledge and useful ✌.

Note: I am always open to suggestions and accept mistakes. So please leave a comment

mohananagavenkat image

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video