ES2021 – ES12 😎

String.protype.replaceAll

const str = "a+b+c+";
console.log(str.replaceAll("+"."-")); // "a-b-c-"
Copy the code

Promise.any

  • Take an array of promise iterables, and if any of them succeed, return the promise that succeeded
  • If all promises fail, return a failed promise
const pErr = new Promise((resolve, reject) = > {
  setTimeout(reject, 1000."1000 pErr." ");
});

const pFast = new Promise((resolve, reject) = > {
  setTimeout(resolve, 2000."2000的pFast");
});

const pSlow = new Promise((resolve, reject) = > {
  setTimeout(resolve, 3000."3000的pSlow");
});

Promise.any([pErr, pSlow, pFast]) // Return the first successful promise
  .then((value) = > {
    console.log(value); // "pFast"
  })
  .catch((err) = > {
    console.log(err); // All promises are triggered when they fail
  });
  
Promise.race([pErr, pSlow, pFast]) // Return the first completed promise
  .then((value) = > {
    console.log(value);
  })
  .catch((err) = > {
    console.log(err);  // "pErr"
  });
Copy the code

Logical assignment operator

  • | | =
  • && =
  • ?? =
var x;
const y = 5;
console.log((x ?? = y));// i.e. : x = x?? 5;
Copy the code

ES2020 – ES11 😃

The operator

JS false values include: undefined, null, 0, NaN, false, “”

  • ??The first argument is not null/undefined, return the second argument
  • ? .When the reference is NULL /undefined, the expression stops evaluating and returns undefined
var person = {
  name: "xx".age: 18
};
console.log(person.hometown? .name);// undefined
Copy the code

ES2019 – ES10 😄