The Top 3 New JavaScript ES 2021 (ES 12) Features I’m Excited About this

Nrlnegii
4 min readNov 17, 2020

The logical assignment operator, Promise.any, and numeric separators

https://support.lensstudio.snapchat.com/hc/en-us/community/posts/360074631191--Fuji-Live
https://support.lensstudio.snapchat.com/hc/en-us/community/posts/360074730792--SAMURAI-BLUE
https://support.lensstudio.snapchat.com/hc/en-us/community/posts/360074631411-Live-Stream
https://pharmacyvillage.com/pha/jp-v-mx-fuji-tv-on01.html
https://pharmacyvillage.com/pha/jp-v-mx-fuji-tv-on02.html
https://pharmacyvillage.com/pha/jp-v-mx-fuji-tv-on03.html
https://pharmacyvillage.com/pha/jp-v-mx-fuji-tv-on04.html
https://pharmacyvillage.com/pha/jp-v-mx-fuji-tv-on05.html
https://pharmacyvillage.com/pha/videos-japon-v-mexico-en-vivo-y-en-directo-v-mx-jp-1wem1.html
https://pharmacyvillage.com/pha/videos-japon-v-mexico-en-vivo-y-en-directo-v-mx-jp-1wem2.html
https://pharmacyvillage.com/pha/videos-japon-v-mexico-en-vivo-y-en-directo-v-mx-jp-1wem3.html
https://pharmacyvillage.com/pha/video-ver-partido-venezuela-v-chile-en-vivo-hoy5-v-ve-cl-1dia1.html
https://pharmacyvillage.com/pha/video-ver-partido-venezuela-v-chile-en-vivo-hoy5-v-ve-cl-1dia2.html
https://pharmacyvillage.com/pha/video-ver-partido-venezuela-v-chile-en-vivo-hoy5-v-ve-cl-1dia3.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-s5851.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-s5852.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-s5853.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-s5854.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-s5855.html
https://pharmacyvillage.com/pha/Japan-v-maxico-Pe2.html
https://pharmacyvillage.com/pha/jp-v-mx-05.html
https://pharmacyvillage.com/pha/j-v-m05j1.html
https://pharmacyvillage.com/pha/j-v-m0509.html
https://pharmacyvillage.com/pha/j-v-m-jp-te-lo-tv-t531.html
https://pharmacyvillage.com/pha/j-v-m-jp-te-lo-tv-t585832.html
https://pharmacyvillage.com/pha/P-v-B-09.html
https://pharmacyvillage.com/pha/U-v-B-viv-tbs01.html
https://pharmacyvillage.com/pha/Ch-v-Ve-03.html
https://pharmacyvillage.com/pha/B-v-U-assistir-tbs01.html
https://www.rodgershealth.org/sites/default/files/webform/jp-nh-k-04.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-nh-k-03.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-nh-k-04.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-nh-k-03.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-nh-k-03.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-nh-k-04.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-nh-k-0e4.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-so-cer-0e4.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-so-cer-0j3.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-so-cer-0c3.pdf
https://www.rodgershealth.org/sites/default/files/webform/jp-so-cer-03.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-nh-k-0e4.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-so-cer-0e4.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-so-cer-0c3.pdf
http://www.ucen.ucsb.edu/sites/www.ucen.ucsb.edu/files/webform/resumes/jp-so-cer-03.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-nh-k-0e4.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-so-cer-0e4.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-so-cer-0c3.pdf
https://mae.rutgers.edu/sites/default/files/webform/jp-so-cer-03.pdf
https://pharmacyvillage.com/pha/Po-v-Cr-1.html
https://pharmacyvillage.com/pha/Po-v-Cr-2.html
https://pharmacyvillage.com/pha/Po-v-Cr-3.html
https://pharmacyvillage.com/pha/Po-v-Cr-4.html
https://pharmacyvillage.com/pha/ja-v-mx-fuji-tv-bt1.html
https://pharmacyvillage.com/pha/ja-v-mx-fuji-tv-bt2.html
https://pharmacyvillage.com/pha/ja-v-mx-fuji-tv-bt3.html
https://pharmacyvillage.com/pha/ja-v-mx-fuji-tv-bt4.html
https://pharmacyvillage.com/pha/P-v-c-pt-1.html
https://pharmacyvillage.com/pha/P-v-c-pt-2.html
https://pharmacyvillage.com/pha/P-v-c-pt-3.html
https://pharmacyvillage.com/pha/f-v-s.1.html
https://pharmacyvillage.com/pha/f-v-s.2.html
https://pharmacyvillage.com/pha/f-v-s.3.html
https://pharmacyvillage.com/pha/f-v-s.4.html
https://pharmacyvillage.com/pha/es-li-vivo-s-v-e12x1.html
https://pharmacyvillage.com/pha/es-li-vivo-s-v-e12x2.html
https://pharmacyvillage.com/pha/es-li-vivo-s-v-e12x3.html
https://pharmacyvillage.com/pha/es-li-vivo-s-v-e12x4.html
https://pharmacyvillage.com/pha/j-v-m-jp-te-lo-tv-t5858x1.html
https://pharmacyvillage.com/pha/j-v-m-jp-te-lo-tv-t5858x2.html
https://pharmacyvillage.com/pha/j-v-m-jp-te-lo-tv-t5858x3.html
https://www.rodgershealth.org/sites/default/files/webform/japan-v-maxico-pe2.html
https://www.rodgershealth.org/sites/default/files/webform/jp-v-mx-05.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m05j1.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m0509.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-t531.html
https://www.rodgershealth.org/sites/default/files/webform/j-v-m-jp-te-lo-tv-t585832.html
https://www.rodgershealth.org/sites/default/files/webform/max-v-jpn-301.html

you can also use this feature.

Photo by Shahadat Rahman on Unsplash.
Thanks to Babel, I’ve been using the new ECMAScript 2021 features for over a year. Almost all the features are useful, but three of them stood out from the pack by saving me a lot of time and making my code more readable.
Let’s go over them.
1. Logical Assignment Operator
The logical assignment operator combines logical operations (like ??, &&, or ||) with an assignment (e.g. =).
Here are some examples.
a ||= b returns a if a is truthy or b if a is falsy.

a &&= b returns b if a is truthy or a if a is falsy.

a ??= b returns b if a is null or undefined, or it returns a if a is truthy.

At first, it was slightly tricky to instantly understand what these operators do during a code review, but after a few weeks, everyone on the team got the hang of it.
2. Promise.any
Promise.any accepts an array of promises and resolves as soon as any of the supplied promises become resolved.
It sounds difficult, so here is an example:

We make three requests simultaneously. When one of the requests resolves, Promise.any also resolves and logs the first resolved request in the console (in our example, it’s Google).
If all promises were rejected, Promise.any throws a new type of error: AggregateError.
What’s new about it is the AggregateError object represents an error where several errors are wrapped in a single error.
Here is how it looks:

e.errors is an array of the errors object.
3. Numeric Separators
Numeric separators give us the ability to separate thousands with an underscore (_) in numeric literals.
How is it useful? It makes our code more informative and readable.
Here is an example:

--

--