The Top 3 New JavaScript ES 2021 (ES 12) Features I’m Excited About
The logical assignment operator, Promise.any, and numeric separators
https://kvt-fastening.at/pan/a-v-d1.html
https://kvt-fastening.at/pan/a-v-d2.html
https://kvt-fastening.at/pan/b-v-m1.html
https://kvt-fastening.at/pan/b-v-m2.html
https://kvt-fastening.at/pan/b-v-m3.html
https://kvt-fastening.at/pan/c-v-a1.html
https://kvt-fastening.at/pan/c-v-a2.html
https://kvt-fastening.at/pan/d-v-t1.html
https://kvt-fastening.at/pan/d-v-t2.html
https://kvt-fastening.at/pan/e-v-g1.html
https://kvt-fastening.at/pan/e-v-g2.html
https://kvt-fastening.at/pan/e-v-g3.html
https://kvt-fastening.at/pan/f-v-a1.html
https://kvt-fastening.at/pan/f-v-a2.html
https://kvt-fastening.at/pan/f-v-a3.html
https://kvt-fastening.at/pan/f-v-y1.html
https://kvt-fastening.at/pan/f-v-y2.html
https://kvt-fastening.at/pan/h-v-r1.html
https://kvt-fastening.at/pan/h-v-r2.html
https://kvt-fastening.at/pan/l-v-e1.html
https://kvt-fastening.at/pan/l-v-e2.html
https://kvt-fastening.at/pan/m-v-c1.html
https://kvt-fastening.at/pan/m-v-c2.html
https://kvt-fastening.at/pan/m-v-f1.html
https://kvt-fastening.at/pan/m-v-f2.html
https://kvt-fastening.at/pan/p-v-x1.html
https://kvt-fastening.at/pan/p-v-x2.html
https://kvt-fastening.at/pan/s-v-b1.html
https://kvt-fastening.at/pan/s-v-b2.html
https://kvt-fastening.at/pan/s-v-q1.html
https://kvt-fastening.at/pan/s-v-q2.html
https://kvt-fastening.at/pan/s-v-z1.html
https://kvt-fastening.at/pan/s-v-z2.html
https://kvt-fastening.at/pan/u-v-e1.html
https://kvt-fastening.at/pan/u-v-e2.html
https://kvt-fastening.at/liv/f-v-r1.html
https://kvt-fastening.at/liv/f-v-r2.html
https://kvt-fastening.at/liv/f-v-r3.html
https://kvt-fastening.at/liv/f-v-r4.html
https://kvt-fastening.at/liv/f-v-r5.html
https://kvt-fastening.at/liv/h-v-r1.html
https://kvt-fastening.at/liv/h-v-r2.html
https://kvt-fastening.at/liv/h-v-r3.html
https://kvt-fastening.at/liv/h-v-r4.html
https://kvt-fastening.at/liv/m-v-j1.html
https://kvt-fastening.at/liv/m-v-j2.html
https://kvt-fastening.at/liv/m-v-j3.html
https://kvt-fastening.at/liv/m-v-j4.html
https://kvt-fastening.at/liv/s-v-e1.html
https://kvt-fastening.at/liv/s-v-e2.html
https://kvt-fastening.at/liv/s-v-e3.html
https://kvt-fastening.at/liv/s-v-e4.html
https://kvt-fastening.at/liv/s-v-t1.html
https://kvt-fastening.at/liv/s-v-t2.html
https://kvt-fastening.at/liv/s-v-t3.html
https://www.espchemicals.com/liv/f-v-r1.html
https://www.espchemicals.com/liv/f-v-r2.html
https://www.espchemicals.com/liv/f-v-r3.html
https://www.espchemicals.com/liv/f-v-r4.html
https://www.espchemicals.com/liv/f-v-r5.html
https://www.espchemicals.com/liv/h-v-r1.html
https://www.espchemicals.com/liv/h-v-r2.html
https://www.espchemicals.com/liv/h-v-r3.html
https://www.espchemicals.com/liv/h-v-r4.html
https://www.espchemicals.com/liv/m-v-j1.html
https://www.espchemicals.com/liv/m-v-j2.html
https://www.espchemicals.com/liv/m-v-j3.html
https://www.espchemicals.com/liv/m-v-j4.html
https://www.espchemicals.com/liv/s-v-e1.html
https://www.espchemicals.com/liv/s-v-e2.html
https://www.espchemicals.com/liv/s-v-e3.html
https://www.espchemicals.com/liv/s-v-e4.html
https://www.espchemicals.com/liv/s-v-t1.html
https://www.espchemicals.com/liv/s-v-t2.html
https://www.espchemicals.com/liv/s-v-t3.html
https://kvt-fastening.at/uf/f-v-s01.html
https://kvt-fastening.at/uf/f-v-s02.html
https://kvt-fastening.at/uf/f-v-s03.html
https://kvt-fastening.at/uf/f-v-s04.html
https://kvt-fastening.at/uf/f-v-s05.html
https://kvt-fastening.at/uf/h-v-p01.html
https://kvt-fastening.at/uf/h-v-p02.html
https://kvt-fastening.at/uf/h-v-p03.html
https://kvt-fastening.at/uf/h-v-p04.html
https://kvt-fastening.at/uf/h-v-p05.html
https://kvt-fastening.at/uf/j-v-m01.html
https://kvt-fastening.at/uf/j-v-m02.html
https://kvt-fastening.at/uf/j-v-m03.html
https://kvt-fastening.at/uf/j-v-m04.html
https://kvt-fastening.at/uf/j-v-m05.html
https://kvt-fastening.at/uf/j-v-m06.html
https://kvt-fastening.at/uf/p-v-v01.html
https://kvt-fastening.at/uf/p-v-v02.html
https://kvt-fastening.at/uf/p-v-v03.html
https://kvt-fastening.at/uf/p-v-v04.html
https://kvt-fastening.at/uf/p-v-v05.html
https://www.espchemicals.com/uf/f-v-s01.html
https://www.espchemicals.com/uf/f-v-s02.html
https://www.espchemicals.com/uf/f-v-s03.html
https://www.espchemicals.com/uf/f-v-s04.html
https://www.espchemicals.com/uf/f-v-s05.html
https://www.espchemicals.com/uf/h-v-p01.html
https://www.espchemicals.com/uf/h-v-p02.html
https://www.espchemicals.com/uf/h-v-p03.html
https://www.espchemicals.com/uf/h-v-p04.html
https://www.espchemicals.com/uf/h-v-p05.html
https://www.espchemicals.com/uf/j-v-m01.html
https://www.espchemicals.com/uf/j-v-m02.html
https://www.espchemicals.com/uf/j-v-m03.html
https://www.espchemicals.com/uf/j-v-m04.html
https://www.espchemicals.com/uf/j-v-m05.html
https://www.espchemicals.com/uf/j-v-m06.html
https://www.espchemicals.com/uf/p-v-v01.html
https://www.espchemicals.com/uf/p-v-v02.html
https://www.espchemicals.com/uf/p-v-v03.html
https://www.espchemicals.com/uf/p-v-v04.html
https://www.espchemicals.com/uf/p-v-v05.html
https://kvt-fastening.at/fog/s-v-h6.html
https://kvt-fastening.at/fog/s-v-h5.html
https://kvt-fastening.at/fog/s-v-h4.html
https://kvt-fastening.at/fog/s-v-h3.html
https://kvt-fastening.at/fog/s-v-h2.html
https://kvt-fastening.at/fog/s-v-h1.html
https://kvt-fastening.at/fog/s-v-g6.html
https://kvt-fastening.at/fog/s-v-g5.html
https://kvt-fastening.at/fog/s-v-g4.html
https://kvt-fastening.at/fog/s-v-g3.html
https://kvt-fastening.at/fog/s-v-g2.html
https://kvt-fastening.at/fog/s-v-g1.html
https://kvt-fastening.at/fog/s-v-f4.html
https://kvt-fastening.at/fog/s-v-f3.html
https://kvt-fastening.at/fog/s-v-f2.html
https://kvt-fastening.at/fog/s-v-f1.html
https://kvt-fastening.at/fog/s-v-e4.html
https://kvt-fastening.at/fog/s-v-e3.html
https://kvt-fastening.at/fog/s-v-e2.html
https://kvt-fastening.at/fog/s-v-e1.html
https://www.espchemicals.com/fog/s-v-h6.html
https://www.espchemicals.com/fog/s-v-h5.html
https://www.espchemicals.com/fog/s-v-h4.html
https://www.espchemicals.com/fog/s-v-h3.html
https://www.espchemicals.com/fog/s-v-h2.html
https://www.espchemicals.com/fog/s-v-h1.html
https://www.espchemicals.com/fog/s-v-g6.html
https://www.espchemicals.com/fog/s-v-g5.html
https://www.espchemicals.com/fog/s-v-g4.html
https://www.espchemicals.com/fog/s-v-g3.html
https://www.espchemicals.com/fog/s-v-g2.html
https://www.espchemicals.com/fog/s-v-g1.html
https://www.espchemicals.com/fog/s-v-f4.html
https://www.espchemicals.com/fog/s-v-f3.html
https://www.espchemicals.com/fog/s-v-f2.html
https://www.espchemicals.com/fog/s-v-f1.html
https://www.espchemicals.com/fog/s-v-e4.html
https://www.espchemicals.com/fog/s-v-e3.html
https://www.espchemicals.com/fog/s-v-e2.html
https://www.espchemicals.com/fog/s-v-e1.html
https://kvt-fastening.at/tue/g-v-s1.html
https://kvt-fastening.at/tue/g-v-s2.html
https://kvt-fastening.at/tue/g-v-s3.html
https://kvt-fastening.at/tue/g-v-s4.html
https://kvt-fastening.at/tue/g-v-s5.html
https://kvt-fastening.at/tue/p-v-c1.html
https://kvt-fastening.at/tue/p-v-c2.html
https://kvt-fastening.at/tue/p-v-c3.html
https://kvt-fastening.at/tue/p-v-c4.html
https://kvt-fastening.at/tue/p-v-c5.html
https://kvt-fastening.at/tue/s-v-f1.html
https://kvt-fastening.at/tue/s-v-f2.html
https://kvt-fastening.at/tue/s-v-f3.html
https://kvt-fastening.at/tue/s-v-f4.html
https://kvt-fastening.at/tue/s-v-f5.html
https://kvt-fastening.at/tue/s-v-g1.html
https://kvt-fastening.at/tue/s-v-g2.html
https://kvt-fastening.at/tue/s-v-g3.html
https://kvt-fastening.at/tue/s-v-g4.html
https://kvt-fastening.at/tue/s-v-g5.html
https://kvt-fastening.at/tue/s-v-g6.html
https://kvt-fastening.at/tue/u-v-s1.html
https://kvt-fastening.at/tue/u-v-s2.html
https://kvt-fastening.at/tue/u-v-s3.html
https://kvt-fastening.at/tue/u-v-s4.html
https://www.espchemicals.com/tue/g-v-s1.html
https://www.espchemicals.com/tue/g-v-s2.html
https://www.espchemicals.com/tue/g-v-s3.html
https://www.espchemicals.com/tue/g-v-s4.html
https://www.espchemicals.com/tue/g-v-s5.html
https://www.espchemicals.com/tue/p-v-c1.html
https://www.espchemicals.com/tue/p-v-c2.html
https://www.espchemicals.com/tue/p-v-c3.html
https://www.espchemicals.com/tue/p-v-c4.html
https://www.espchemicals.com/tue/p-v-c5.html
https://www.espchemicals.com/tue/s-v-f1.html
https://www.espchemicals.com/tue/s-v-f2.html
https://www.espchemicals.com/tue/s-v-f3.html
https://www.espchemicals.com/tue/s-v-f4.html
https://www.espchemicals.com/tue/s-v-f5.html
https://www.espchemicals.com/tue/s-v-g1.html
https://www.espchemicals.com/tue/s-v-g2.html
https://www.espchemicals.com/tue/s-v-g3.html
https://www.espchemicals.com/tue/s-v-g4.html
https://www.espchemicals.com/tue/s-v-g5.html
https://www.espchemicals.com/tue/s-v-g6.html
https://www.espchemicals.com/tue/u-v-s1.html
https://www.espchemicals.com/tue/u-v-s2.html
https://www.espchemicals.com/tue/u-v-s3.html
https://www.espchemicals.com/tue/u-v-s4.html
https://kvt-fastening.at/uf/j-v-m07.html
https://kvt-fastening.at/uf/j-v-m08.html
https://kvt-fastening.at/uf/j-v-m09.html
https://kvt-fastening.at/pop/c-v-p1.html
https://kvt-fastening.at/pop/c-v-p2.html
https://kvt-fastening.at/pop/c-v-p3.html
https://kvt-fastening.at/pop/c-v-p4.html
https://kvt-fastening.at/pop/f-v-s1.html
https://kvt-fastening.at/pop/f-v-s2.html
https://kvt-fastening.at/pop/f-v-s3.html
https://kvt-fastening.at/pop/f-v-s4.html
https://kvt-fastening.at/pop/J-v-P1.html
https://kvt-fastening.at/pop/J-v-P2.html
https://kvt-fastening.at/pop/J-v-P3.html
https://kvt-fastening.at/pop/J-v-P4.html
https://kvt-fastening.at/pop/m-v-j1.html
https://kvt-fastening.at/pop/m-v-j2.html
https://kvt-fastening.at/pop/m-v-j3.html
https://kvt-fastening.at/pop/m-v-j5.html
https://kvt-fastening.at/pop/P-v-c1.html
https://kvt-fastening.at/pop/P-v-c2.html
https://kvt-fastening.at/pop/P-v-c3.html
https://www.espchemicals.com/pop/c-v-p1.html
https://www.espchemicals.com/pop/c-v-p2.html
https://www.espchemicals.com/pop/c-v-p3.html
https://www.espchemicals.com/pop/c-v-p4.html
https://www.espchemicals.com/pop/f-v-s1.html
https://www.espchemicals.com/pop/f-v-s2.html
https://www.espchemicals.com/pop/f-v-s3.html
https://www.espchemicals.com/pop/f-v-s4.html
https://www.espchemicals.com/pop/J-v-P1.html
https://www.espchemicals.com/pop/J-v-P2.html
https://www.espchemicals.com/pop/J-v-P3.html
https://www.espchemicals.com/pop/J-v-P4.html
https://www.espchemicals.com/pop/m-v-j1.html
https://www.espchemicals.com/pop/m-v-j2.html
https://www.espchemicals.com/pop/m-v-j3.html
https://www.espchemicals.com/pop/m-v-j5.html
https://www.espchemicals.com/pop/P-v-c1.html
https://www.espchemicals.com/pop/P-v-c2.html
https://www.espchemicals.com/pop/P-v-c3.html
https://kvt-fastening.at/him/k-v-r1.html
https://kvt-fastening.at/him/k-v-r2.html
https://kvt-fastening.at/him/k-v-r3.html
https://kvt-fastening.at/him/p-v-a1.html
https://kvt-fastening.at/him/p-v-a2.html
https://kvt-fastening.at/him/p-v-a3.html
https://kvt-fastening.at/him/r-v-a1.html
https://kvt-fastening.at/him/r-v-a2.html
https://kvt-fastening.at/him/r-v-a3.html
https://kvt-fastening.at/him/t-v-s1.html
https://kvt-fastening.at/him/t-v-s2.html
https://kvt-fastening.at/him/t-v-s3.html
https://www.espchemicals.com/fib/k-v-r1.html
https://www.espchemicals.com/fib/k-v-r2.html
https://www.espchemicals.com/fib/k-v-r3.html
https://www.espchemicals.com/fib/p-v-a1.html
https://www.espchemicals.com/fib/p-v-a2.html
https://www.espchemicals.com/fib/p-v-a3.html
https://www.espchemicals.com/fib/r-v-a1.html
https://www.espchemicals.com/fib/r-v-a2.html
https://www.espchemicals.com/fib/r-v-a3.html
https://www.espchemicals.com/fib/t-v-s1.html
https://www.espchemicals.com/fib/t-v-s2.html
https://www.espchemicals.com/fib/t-v-s3.html
https://kvt-fastening.at/sam/c-v-p1.html
https://kvt-fastening.at/sam/c-v-p2.html
https://kvt-fastening.at/sam/f-v-s1.html
https://kvt-fastening.at/sam/f-v-s2.html
https://kvt-fastening.at/sam/l-v-a1.html
https://kvt-fastening.at/sam/l-v-a2.html
https://kvt-fastening.at/sam/s-v-g1.html
https://kvt-fastening.at/sam/s-v-g2.html
https://kvt-fastening.at/sam/s-v-u1.html
https://kvt-fastening.at/sam/s-v-u2.html
https://www.espchemicals.com/sa/c-v-p1.html
https://www.espchemicals.com/sa/c-v-p2.html
https://www.espchemicals.com/sa/f-v-s1.html
https://www.espchemicals.com/sa/f-v-s2.html
https://www.espchemicals.com/sa/l-v-a1.html
https://www.espchemicals.com/sa/l-v-a2.html
https://www.espchemicals.com/sa/s-v-g1.html
https://www.espchemicals.com/sa/s-v-g2.html
https://www.espchemicals.com/sa/s-v-u1.html
https://www.espchemicals.com/sa/s-v-u2.html
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: