JavaScript ES2021 🚀

It's expected to be released in June 2021.

Let's go through some of the new features that we're getting from this version 👇
🔸 String.prototype.replaceAll()

The current 'String.prototype.replace()' method only replaces the first occurrence, unless a regular expression with a global modifier is provided.

With the new 'String.prototype.replaceAll()' method, we can finally omit the regex 👇
🔸 Private Methods

When a method name starts with '#', we declare them private.
Private methods can only be accessed from within the class they're defined 👇
🔸 Private Accessors

Similar to Private Methods, accessor functions can be made private by prepending # to the function name as well 👇
🔸 Promise.any()

You probably already know how to use 'Promise.all()' to await all Promises from a list to resolve.

With Promise.any(), we can await a list of Promises, but resolve as soon as one of the Promises in the list resolves 👇
🔸 Logical Assignment Operator (&&)

The new Logical Assignment Operator combines logical operations (&& / || / ??) with assignments.

Let's take a look below, using && 👇
🔸 Logical Assignment Operator (||)

Similarly, we can use the new Logical Assignment Operator with || 👇
🔸 Logical Assignment Operator (??)

Finally, we can use it in combination with the Nullish Coalescing Operator 👇
There are two additional new features, 'WeakRef' and 'Finalizers', which are a bit too complex to explain here.
But I highly recommend looking them up!

What do you think of these new features? 🤩
Will you be using them?

Share your thoughts below 👇
You can follow @SimonHoiberg.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.