In this Blog we are going to learn ES 2020 Key Features.ES2020 released on Start of this year.
Here we are going to learn some really cool features of ES 2020
Let’s start with Feature 1 : Nullish coalescing
Use when the value is missing (undefined or null (It doesn’t work with NaN , ‘’, 0)).
The undefined and null are the nullish value , and you want to handle it then we use nullish coalescing operator.
In above example , country is not there so it does show undefined And I want to print some meaningful result
Before ES 2020 we use truthy and falsy
It just checks if the first value is true then don’t go to the second value ,
if first is false (undefined or null ) then go to the second value.
Instead of PIPE Now Use Nullish Operator from ES 2020
Feature 2 : Optional Chaining Operator
Nested Object Property access can be dangerous , if any of the property is null or undefined.
Feature 3 : globalThis
So the problem is If u want to write code which must run on all of the environment , u need to detect the environment
Now ES 2020 provide the globalThis and it is standard for all the environment. You can use the globalThis on node js or JS Env.
Feature 4 : Promise.allSettled (ES2020)
Promise.all rejects as a whole if any promiserejects. That’s good for “all or nothing” cases, when we need all results successful to proceed: Promise.allSettled just waits for all promises to settle, regardless of the result.
- Promise.all rejects as soon as a promise having any rejected promise.
- Promise.allSettled resolves regardless of rejected or resolved promise encounter. It collect all the promises and show the result.
Feature 5: BigInt
BigInt is a new numeric Data Type in JS. It store the value more than 2^53-1