ES2021 is the latest version of the EcmaScript specification as of 2021.
In this article, we’ll look at the new features that come with ES2021.
ECMA in 2021 brings new features such as a string replaceAll function, number literals, weak refs, and logical operator assignment! In this video, we take a look at examples and breakdown of how each feature works.
Today, in June 2021, these features, along with others, have been approved.
In this article, I elaborate and detail what I wrote more than a year ago, but with the addition of the final features that have been approved.
String.prototype.replaceAll() replace all instances of a substring in a string with another string value, without using a global regexp.
Until now, the most common way of doing this was to use a global regexp.
Consider the following code where we use a regular expression to replace the “+” character with an empty character:
const fullname= 'fullname=Jhon+Hannibal+Smith'; const fullnameFormated = fullname.replace(/\+/g, ' '); //output: Jhon Hannibal Smith
This approach has the downside of requiring a regular expression that uses special characters to achieve this. But the use of regular expressions is not easy and is error-prone and a common source of bugs.
ES2021 is the version of ECMAScript corresponding to the year 2021. This version doesn’t include as many new features as those that appeared in ES6 (2015). However, some useful features have been incorporated.
This article introduces the features provided by ES2021 in easy code examples. In this way, you can quickly understand the new features without the need for a complex explanation.
➡️ Logical assignment operators
➡️ Numeric separators