DEV Community

Mohana Naga Venkat Sayempu
Mohana Naga Venkat Sayempu

Posted on

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)