Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

JS Tutorial

JS Syntax

JS Operators

JS If Conditions

JS Loops

JS Strings

JS Numbers

JS Functions

JS Objects

JS Scope

JS Dates

JS Temporal  New

JS Arrays

JS Sets

JS Maps

JS Iterations

JS Math

JS RegExp

JS Data Types

JS Errors

JS Debugging

JS Style Guide

JS Reference

JS Projects New

JS 2026

JS HTML DOM

JS HTML Events


JS Advanced


JS Functions

JS Objects

JS Classes

JS Asynchronous

JS Modules

JS Meta & Proxy

JS Typed Arrays

JS DOM Navigation

JS Windows

JS Web API

JS AJAX

JS JSON

JS jQuery

JS Graphics

JS Examples

JS Reference


ECMAScript 2021


New Features in JavaScript 2021

FeatureDescription
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:

Chrome
85
Edge
85
Firefox
79
Safari
14.1
Opera
71
Aug 2020 Aug 2020 Jul 2020 Apr 2021 Sep 2020

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);
});
Try it Yourself »

JavaScript String ReplaceAll()

ES2021 introduced the string method replaceAll():

Example

text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");
Try it Yourself »

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");
Try it Yourself »

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;
Try it Yourself »

The numeric separator is only for visual use.

Example

const num1 = 1_000_000_000;
const num2 = 1000000000;
(num1 === num2);
Try it Yourself »

The numeric separator can be placed anywhere in a number:

Example

const num1 = 1_2_3_4_5;
Try it Yourself »

The numeric separator is not allowed at the beginning or at the end of a number.

In JavaScript only variables can start with _.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->