Numeric Separators in JavaScript
In this post, we are going to learn about Numeric Separators in JavaScript and why it is useful.
![Numeric Separators in JavaScript](/content/images/size/w2000/2021/06/Green-and-White-Illustration-Science-Class-Education-Presentation--12---1-.png)
Numeric separators enable us to make our numeric literals more readable by creating a visual separation between groups of digits. It is so useful especially working with large numbers. As you can see it's very hard to read.
const quantity = 100000000000;
Let's apply numeric separators to quantity variable
const quantity = 100_000_000_000;
However, there are some limitations for numeric separators.
It cannot be used at the beginning and end of the number
const quantity = 1000_;
// its a valid variable name actually.
const quantity = _1000;
Consecutive underscore is not allowed and you can only put underscores between two digits.
const quantity = 10000__00;
const pi = 3_.141
const pi = 3._141
To check about browser support of numeric separators.