JavaScript Features You Need to Look At

tmchuynh

Tina Huynh

Posted on March 26, 2022

JavaScript Features You Need to Look At

ECMAScript 2022 is right around the corner, but there were many exciting features that were introduced last year:

replaceAll method

const message = "A-message-being-divided";
const processedMessage = message.replaceAll('-', ' ');
Enter fullscreen mode Exit fullscreen mode

With replaceAll(), you can replace a given character or set of characters in a string with something else. It takes two arguments - the value you want to replace and the value you want to replace it with.

Promise.any()

With Promise.any(), you are able to return a promise that resolves as soon as any of the promises passed inside the promise array parameter is fulfilled. If none are, an AggregateError will be thrown.

Logical Assignment Operators

These can help make code shorter and cleaner! There is the OR & Equals (||=) , And & Equals (&&=), and nullish coalescing assignment operator (??=)

Numeric Separators

The separators allow you to add underscores between digits, which makes them more readable.

let n1 = 1_000_000_000;
console.log(n1) // This will print:1000000000
Enter fullscreen mode Exit fullscreen mode

WeakRef

WeakRef stands for Weak References and allows you o create a weak reference to an object. This is a reference that does not prevent the object from being reclaimed by the garbage collector.

Conclusion

There are always new methods and developments to learn that enhance our code. What are some of your favorite JavaScript features you use the most often? Always love hearing from everyone!

Happy coding!

Buy Me A Coffee

💖 💪 🙅 🚩
tmchuynh
Tina Huynh

Posted on March 26, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related