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 🙏
• • •
Missing some Tweet in this thread? You can try to
force a refresh
🎯 The challenge
Write a function that — given a string — returns true if the string is a palindrome or false otherwise.
Let's look at 11 different approaches to solving this in JavaScript 👇🧵
👌 The definition
A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as taco cat or madam or racecar or the number 10801.
- Wikipedia
According to the definition, we need to strip potential non-alphanumeric characters thus convert to lower-case.
So in all of the following solutions, we will be using a "clean" function to get a clean sequence of characters.