🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #129

JS 2021


New Features in JavaScript 2021

Col 1 Col 2 Col 3 Col 4
Feature Description
Promise.any() Takes promises as input and returns a single promise
String replaceAll() Replaces all occurrences of a substring in a string
Numeric Separator New numeric separator (_) makes numbers more readable

Browser Support

ECMAScript 2021 is supported in all modern browsers since April 2021:


JavaScript Promise.any()

Promise.any() is a static method in JavaScript that takes an iterable of Promises as input and returns a single Promise.

Example

// Create a Promise

const myPromise1 = new Promise((resolve, reject) => {

  setTimeout(resolve, 200, "King");

});

// Create another Promise

const myPromise2 = new Promise((resolve, reject) => {

  setTimeout(resolve, 100, "Queen");

});

// Run when any promise fulfill

Promise.any([myPromise1, myPromise2]).then((x) => {

  myDisplay(x);

});

JavaScript String ReplaceAll()

ES2021 introduced the string method replaceAll():

Example

text = text.replaceAll("Cats","Dogs");

text = text.replaceAll("cats","dogs");

The replaceAll() method allows you to specify a regular expression instead of a string to be replaced.

If the parameter is a regular expression, the global flag (g) must be set, otherwise a TypeError is thrown.

Example

text = text.replaceAll(/Cats/g,"Dogs");

text = text.replaceAll(/cats/g,"dogs");

Note: ES2020 introduced the string method matchAll().


JavaScript Numeric Separator (_)

ES2021 intoduced the numeric separator (_) to make numbers more readable:

Example

const num = 1_000_000_000;

The numeric separator is only for visual use.

Example

const num1 = 1_000_000_000;

const num2 = 1000000000;

(num1 === num2);

The numeric separator can be placed anywhere in a number:

Example

const num1 = 1_2_3_4_5;

Note: The numeric separator is not allowed at the beginning or at the end of a number. In JavaScript only variables can start with _.

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS 2021 – FAQs

Quick answers about learning JS 2021 in JavaScript.

This free note from CodingNow 2.0 explains JS 2021 in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including JS 2021, is 100% free with no signup required.
With focused practice, most students grasp JS 2021 in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now