Simon HΓΈiberg Profile picture
Startup CEO ‧ Building a portfolio of bootstrapped SaaS products.

Sep 16, 2021, 11 tweets

JavaScript ES2021 πŸš€
It's here!!

Are you up to speed with some of the cool new features we got in ES2021?

Let's take a look πŸ‘‡πŸ§΅

JavaScript ES2021 (or ES12) - was published in June 2021 and introduces some cool new features to the JavaScript language.

Should you care?!

Well, it's not groundbreaking (like ES6), but it does introduce some features that you should familiarize yourself with.

Let's dive in!

πŸ”Έ 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.

If you're using ESNEXT in your projects, you're probably already using some of these. I think they are really cool πŸ™Œ

I hope you enjoyed reading!

Take a second to like and retweet this thread.
In that way, people from your own network get to enjoy as well.

Thank you πŸ™

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling