Key words of knowledge circle:

Es12, New feature.

Abstract:

ES12 was released in June 2021, so here’s a look at the new features planned for release.

features

  • String.prototype.replaceAll()
  • Promise.any
  • WeakRef
  • &&=, ||= and ?? =
  • Numeric separators

Here’s a look at them all:

String.prototype.replaceAll()

Instead of using regular replacements, you can now use a shortcut; ReplaceAll.

/ / before 'jxvxscript. Replace (/ x/g,' a '); Jxvxscript becomes javascript 'jxvxscript'. ReplaceAll ('x', 'a');Copy the code

Promise.any

Promise.any() receives a Promise iterable and returns the Promise that succeeded as soon as one of the promises succeeds.

If none of the iterable promises succeeds (i.e. all promises fail/reject), return a failed promise

Const promise1 = new Promise((resolve, reject) => reject(' I am a failure ')); Const promise2 = new Promise((resolve, reject) => reject(' I am a failure ')); const promiseList = [promise1, promise2]; Promise.any(promiseList).then(values=>{ console.log(values); }) .catch(e=>{ console.log(e); });Copy the code

WeakRefs

WeakRefs Class creates a weak reference to an object (a weak reference to an object means that it does not prevent the GC from collecting when the object should be collected by the GC)

Logical Assignment Operators

Including: these operators && =, | | =,?????? =;

a = 1; b = 2; A &&=b // a=2 /* The above code is equivalent to a&& a= b?? = ACTS as if (a = = null | | a = = undefined) {} a = b * /Copy the code

Numeric Separators — Numeric Separators

Numbers add separators. You can use _ to separate numbers to make it easier to read larger numbers

For those of you who deal more with numbers, it might be more comfortable

// previous syntax before ES12 const number = 92145723; // new syntax coming with ES12 const number = 92_145_723; Console. log(number) // 92145723 // const number = 1_0000; console.log(number) // 10000Copy the code

Chrome is awesome! So fast!