DEV Community

New Features in ECMAScript 2021 (with code examples)

Faithful Ojebiyi on March 09, 2021

In this tutorial we are going to learn about the new features we can use in the latest version of ECMAScript 2021 with some coding examples ...
Collapse
 
nicozerpa profile image
Nico Zerpa (he/him)

Great post, Faithful!
The numeric separators are extremely handy, love them. I'll be using private methods a lot.

By the way, if someone is asking why JavaScript uses the # symbol for its private properties and not the private keyword, in this comment from the ECMA committee they explain why.

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

Thanks for pointing that out I forgot to include that in this post.

Collapse
 
tarektouati profile image
Tarek Touati

Great Post !

Can you please explain the difference between
Promise.race and Promise.any ?
They booth act the same ? Does Promise.race have been deprecated ?

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

They are a bit different
Promise.race is resolved as soon as any of the promises you feed it resolves, whether they are fulfilled or rejected. Promise.any is settled as soon as any of the promises you feed it is fulfilled or all the promises are rejected. If all promises are rejected it returns an AggregateError.

So Promise.race returns a promise that is settled regardless it being resolved or rejected. But promise.any will not return if one promise is rejected. It will continue until the first resolved promise. If in any case none of the promises resolves then it returns an AggregateError.
I hope I cleared your confusion

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

Promise.race() isn't deprecated either.. They have different use cases

Collapse
 
martijn_scheffer_f5485f4b profile image
Martijn Scheffer • Edited

WHEN does Promise.any throw an error ? how can it know that none of the promise will be resolved later ?

did you mean that when ALL promises are rejected an exception is thrown ? that isn't exactly the same

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

When you use Promise.any, your literally saying which ever promise resolves first. It would only throw an error if non resolves.

If you want to make sure all your promise resolves or you want to catch error when any of the promises is rejected you should use Promise.all instead

Collapse
 
pawandeore profile image
pawan deore

Nice Post

Collapse
 
consciousness_dev profile image
Ario Setiawan

Finally Promise.any solve my error handling easily! ( 0 )

Collapse
 
xexnon profile image
Xexnon

Seems like I'll be using the replace all method frequently, and the numeric separators will come in really handy... A detailed, well written, explanatory post. Keep it up!

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

Very true the replaceAll method and the numeric separators were really needed.
I see myself using the private methods and accessors alot

Collapse
 
abulka profile image
Andy Bulka

Running the code above gives me Invalid character: '#'

Collapse
 
faithfulojebiyi profile image
Faithful Ojebiyi

Update your chrome browser if thats what you are using.

Collapse
 
mkorkut profile image
Korkut

it was a great article thanks

Collapse
 
radix018 profile image
Rahul

Quite informative. I got to learn about the new operators, kinda tricky though, the Promise.all also looks very promising.