Loading lesson path
Promise.any() Takes promises as input and returns a single promise
Replaces all occurrences of a substring in a string
New numeric separator (_) makes numbers more readable
ECMAScript 2021 is supported in all modern browsers since
85
85
79
14.1
71
JavaScript Promise.any() Promise.any() is a static method in JavaScript that takes an iterable of Promises as input and returns a single Promise.
// 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);
});Example text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");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");
ES2020 introduced the string method matchAll().
JavaScript Numeric Separator (_)
ES2021 intoduced the numeric separator (_) to make numbers more readable:const num = 1_000_000_000;The numeric separator is only for visual use.
const num1 = 1_000_000_000;
const num2 = 1000000000;
(num1 === num2);The numeric separator can be placed anywhere in a number:
const num1 = 1_2_3_4_5;The numeric separator is not allowed at the beginning or at the end of a number. In JavaScript only variables can start with _.