JavaScript ES2021

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 👇

No alt text provided for this image

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 👇

No alt text provided for this image

Private Accessors

Similar to Private Methods, accessor functions can be made private by prepending # to the function name as well 👇

No alt text provided for this image

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 👇

No alt text provided for this image

Logical Assignment Operator (&&)

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

Let's take a look below, using && 👇

No alt text provided for this image

Logical Assignment Operator (||)

Similarly, we can use the new Logical Assignment Operator with || 👇

No alt text provided for this image

Logical Assignment Operator (??)

Finally, we can use it in combination with the Nullish Coalescing Operator 👇

No alt text provided for this image

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 in the comments.

Adam Purdy

Motivated individual currently expanding my knowledge of Information Technology!

4y

Thanks for breaking it down, very easy read. :)

Like
Reply
Yoel Morad

Staff Software Engineer at NABX

4y

Lovely read! Thank you for this one, Simon.

To view or add a comment, sign in

Others also viewed

Explore topics