Jean Paul Giraldo

Hello, I'm Jean Paul Giraldo! A Software Developer by day, maker and lifelong learner by night (or very early mornings).

JavaScript Latest Features (2020)

Number 2020 on fire Photo by Evie S. on Unsplash

I think we can all agree 2020 was a horrible year. For everybody. But it also brought some really cool features to JavaScript that I've been waiting for a long time. This is not an exhaustive list of ALL the features ECMAScript made available this year, but they're the top 5 I'm most excited about.

1) BigInt

It returns a bigint primitive to represent whole numbers larger than 253 - 1, which is the largest number JS can represent. Number.MAX_SAFE_INTEGER.

Snippet of code showing an example of BigInt

2) Dynamic imports

Now we can import JavaScript files dynamically as modules. Allowing us to only import modules when and if we need them.

Imagine we have two files, each with data for a specific user.

Snippet of code of a Javascript Snippet of code of a Javascript

Now in a separate third file we can import them dynamically and chain the response using .then() like this:

Snippet of code of a Javascript

Or, we can use an async function like this:

Snippet of code of a Javascript

3) Nullish Coalescing ??

With this handy new ?? operator we can trully check for nullish values, that is, if a value is either null or undefined. As oposed to other operators like || that check for falsey values.

Snippet of code of a Javascript Snippet of code of a Javascript

4) Optional Chaining ?.

This is hands down my favorite new feature. I've been waiting for this one for some time. You can access nested object properties while checking if the property exists or not. If you try to access the properties of a property that doesn't exist you get a gentle undefined, as opposed to Uncaught TypeError: Cannot read property of undefined. Check it out.

Snippet of code showing an example of BigInt

5) Promise.allSettled()

This new JS feature waits for all promises to be settled (resolved or rejected) and returns an array of objects with the status and reason for every promise.

Snippet of code showing an example of BigInt