DEV Community

Cover image for JavaScript Features You Need to Look At
Tina Huynh
Tina Huynh

Posted on • Updated on

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

Top comments (10)

Collapse
 
curiousdev profile image
CuriousDev

Thank you, @tmchuynh ! These points are understandable and useful, but do you also know why we would use Weak Ref?

Collapse
 
peerreynders profile image
Collapse
 
tmchuynh profile image
Tina Huynh

Why is that?

Collapse
 
diballesteros profile image
Diego (Relatable Code)

replaceAll definitely simplifies a lot of operations

Collapse
 
camco profile image
Camco

Wow Great Post!!
I cannot believe I didn't know about promise.any()

Collapse
 
tmchuynh profile image
Tina Huynh

Thanks! :D Always learning something new everyday

Collapse
 
eve profile image
Eve

Thank your share

Collapse
 
tmchuynh profile image
Tina Huynh

glad it could be of help to you

Collapse
 
tmchuynh profile image
Tina Huynh

Ahhh <3 always learning every day. Thanks for explaining

Collapse
 
davidwebdev profile image
David Haz

Nice one! :)