ES2020 is here!
The fresh new and improved specification of JavaScript 🚀

Let me take you through some of the cool new things that we get!
These are my 5 favorite new features
🔥 Dynamic import

With this new feature, we can import JavaScript modules dynamically, as we need it.

This pattern is also known as code-splitting, and with ES2020 we can do this natively instead of relying on tools like Webpack.
🔥 Optional Chaining

With this feature, we can now access deeply nested properties without having to null-check.

Notice how 'quxBaz' becomes undefined instead of throwing a reference error.
🔥 Nullish Coalescing

With Nullish Coalescing, we can now evaluate values that are 'nullish', not just 'falsy'.

Notice how the variable 'foo' is falsy, but not nullish (null or undefined).
In some cases, we want to use fallbacks only in the case of null or undefined.
🔥 globalThis

If you want to reuse the same code across different runtimes, you'll run into trouble with the global object.

globalThis will reference 'window' in browsers, 'global' in Node.js, and 'self' in Web Workers.

Now we don't have to manually detect the runtime anymore.
🔥 Promise.allSettled

With this new member of Promise, we can accept an array of Promises and only resolve when all of them are settled. Either resolved or rejected.

This enables us to run all promises without caring if they're resolved or rejected.
You can follow @SimonHoiberg.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: