Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Starting in 2016, versions have been named by year, like ES2016, ES2018, ES2020, and so on.
WarningThese features are relatively recent, so older browsers may require alternative code or a polyfill for compatibility. |
// 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); }); |
Promise.any() has been supported in all modern browsers since September 2020.
ES2021 added the replaceAll() method to strings.
text = text.replaceAll(“Cats”,“Dogs”); text = text.replaceAll(“cats”,“dogs”); |
The replaceAll() method allows you to use a regular expression instead of a string for replacements. If a regular expression is provided, the global flag (g) must be set; otherwise, a TypeError will be thrown.
text = text.replaceAll(/Cats/g,“Dogs”); text = text.replaceAll(/cats/g,“dogs”); |
ES2021 intoduced the numeric separator (_) to make numbers more readable:
const num = 1_000_000_000; |
The numeric separator is purely for visual clarity.
const num1 = 1_000_000_000; const num2 = 1000000000; (num1 === num2); |
The numeric separator can be inserted anywhere within a number.
const num1 = 1_2_3_4_5; |
Note: The numeric separator cannot appear at the beginning or end of a number. In JavaScript, only variables can begin with an underscore (_). |
The numeric separator has been supported in all modern browsers since January 2020.