Since 2016 versions are named by year.
New Features in ES2021
- Promise any():
const first = await Promise.any([prom1,prom2,prom3]);
- String replaceAll()
- Numeric Separators (_)
These features are relatively new. Old browser may need an alternative code (Polifill)
ES2021 introduced the string method
text = text.replaceAll("cats","dogs");
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 set, otherwise a TypeError is thrown.
text = text.replaceAll(/cats/g,"dogs");
ES2020 introduced the string method matchAll().
ES2021 intoduced the numeric separator (_) to make numbers more readable:
The numeric separator is only for visual use.
const num2 = 1000000000;
(num1 === num2);
The numeric separator can be placed anywhere in a number:
The numeric separator is not allowed at the beginning or at the end of a number.
The numeric separator is supported in all browsers since January 2020:
|Chrome 75||Edge 79||Firefox 74||Safari 13.1||Opera 67|
|Jun 2019||Jan 2020||Oct 2019||Sep 2019||Jun 2019|