Your friend John's digital garden

Await an Async Function and Do Something with it in One Line of Javascript

August 23, 2020

Have you ever wanted a one-liner that let’s you await the result of a function and do some further processing?

Instead of:

const resp = await fetch('https://api.github.com/users/johnomarkid')
const body = await json()

You want a way to skip declaring a resp constant and get directly to the body.

Here’s some syntactical sugar in Javascript that let’s you do just that.

const body = (await fetch('https://api.github.com/users/johnomarkid')).json()

Tuesday Brew

Curated finds from my week, mostly about coding, job opportunities and whatever else catches my eye. I also include new posts to my digital garden.

    I won’t send you spam.

    Unsubscribe at any time.

    Written by John Omar who lives and works remotely building useful things. You should follow him on Twitter