JavaScriptIntermediate#async

How does async/await work?

async marks a function as returning a promise; await pauses that function until the awaited promise settles, without blocking the main thread. Errors are handled with try/catch.

Example
async function load() {
  try {
    const res = await fetch('/api/users');
    return await res.json();
  } catch (e) {
    console.error('failed', e);
  }
}

Related Questions

1
JavaScriptIntermediate#async#performance

How do you run async calls in parallel with async/await?

Open
2
JavaScriptBeginner#async

What is callback hell and how do you avoid it?

Open
3
JavaScriptIntermediate#dom#events

What is event bubbling, capturing and delegation?

Open