JavaScript ES2021 Features You Need to Know
JavaScript is one of the more popular programming languages, especially in web development. Thanks to the ECMAScript versions, a lot of new useful features are being released in JavaScript every year. ECMAScript 2021 has come out with some interesting and powerful features that we can use in JavaScript. They have not been released yet, but we are able to have a look at them.
In this article, we will discover some useful ES2021 features that you need to know in JavaScript. Let’s get right into it.
Numeric Separators
Numeric separators is one of the useful features that have been introduced in ES2021. They make it easier to read large numbers in JavaScript by providing separation between digits using underscores _.
Take a look at the example below:
let myNumber = 1_000_000;
console.log(myNumber); //output: 1000000
let num = 0.000_0002;
console.log(num); //output: 2e-7
This makes it much easier to read big numbers when editing your code.
Replace All
The method replaceAll() is one of the features I really like about ES2021. This method allows you to replace all the characters that you specify in a string without using a regex.
The method replaceAll() takes two parameters: the character we want to replace and the character we want to replace it by.
The following example will help you understand it more:
let myStr = ‘Prograssing’;
console.log(myStr.replaceAll(“s”, “m”)); //output: Programming
As you can see, we replaced all the s characters with m characters using replaceAll(). This allows you to easily replace stuff on strings, you don’t need to use regex anymore in such cases.
Final Thoughts
ES2021 has come with useful JavaScript features to make the life of the developer much easier. That’s why we always need to stay updated with the latest technologies.
Thank you for reading this article. I hope you found it useful.