ES2020 Cool Stuff Reminder

- 100 words (1mn)

- lovethebomb

Categories: notes

As a small self-reminder, here are some useful features of the upcoming useful additions in ES2020 in my opinion.

Optional Chaining (?.)

const user = { name: "Foo" }

user.settings && user.settings.theme => undefined
user.settings?.theme => undefned

MDN Optional Chaining

Nullish Coalescing Operator (??)

Returns right hand when false

const username = user && user.name ? user.name : 'anonymous'

const username = user && user.name ?? 'anonymous'

// Even simpler with optional chaining
const username = user?.name ?? 'anonymous'

MDN Nullish Coalescing Operator

Dynamic Import (await import)

Supports async/await!

async somethingAsync() => {
    await import ('./widgets/big-async-widget')
}

MDN Dynamic Imports

Served by ilotreseau.net Hugo 0.71.0 7c7362c