Numeric Separators (_)

Numeric Separators (_) in JavaScript (ES2021/ES2022) allow improved readability by placing underscores as visual separators in large numbers for better code comprehension.

Syntax:

let num1 = 1_000_000_000;

Example: Here is the basic example of above method.

Javascript




let num1 = 1_000_000_000;
let num2 = 1000000000;
console.log(num1 === num2);


Output

true



ECMAScript 2021 (JS 2021/2022)

JavaScript in 2021/2022 continues to evolve, with ES2021/ES2022 bringing enhanced features like private class fields, promise improvements, and record data structures, boosting developer productivity and code quality.

Similar Reads

JavaScript New Features in ES2021

...

JavaScript in 2022 new features :

Name Description Array at() Retrieves element at index supports positive and negative indexing String at() Finds character at index, supports positive and negative indexing RegExp /d Matches any digit (0-9) in a regular expression pattern. Object.hasOwn() Checks if object has its own specified property. error.cause Accesses the cause of an error in the error object. await import Awaits and imports a module dynamically in JavaScript code asynchronously. Private methods and fields Encapsulates data with restricted access using private methods and fields. Class field declarations Defines class properties directly without constructor using concise syntax....

Method 1: Promise any()

Promise.any() is a JavaScript ES2021/ES2022 method that takes an array of Promises and returns the first resolved Promise, rejecting only if all Promises reject....

Method 2: String replaceAll()

...

Method 3: Numeric Separators (_)

String replaceAll() is a JavaScript method (ES2021/ES2022) replacing all occurrences of a substring with another, returning a new string....

Method 4: Array at()

...

Method 5: String at()

Numeric Separators (_) in JavaScript (ES2021/ES2022) allow improved readability by placing underscores as visual separators in large numbers for better code comprehension....

Method 6: RegExp \D

...

Method 7: Object.hasOwn()

The JavaScript Array at() method takes an integer value (index) as a parameter and returns the element of that index. It allows positive and negative integers. For the negative integer, it counts back from the last element in the array....