async-await

await

Pauses execution of the surrounding async function until the awaited promise settles, then resumes with its resolved value. If the promise rejects, await throws the reason, letting you use try/catch.

await expression

Parameters

Parameter Purpose
value Non-promise operands are wrapped and returned as-is
rejection Rejected promises throw — catch with try/catch
context Only valid inside async functions or at the top level of an ES module

Examples

async function main() {
  const res = await fetch('/api');
  const data = await res.json();
  console.log(data);
}

Sequential awaits — each waits for the previous to complete.

// Parallel, not sequential
const [a, b] = await Promise.all([loadA(), loadB()]);

Kick off both promises before awaiting to run them concurrently.

// Anti-pattern: sequential when you meant parallel
const a = await loadA();
const b = await loadB(); // waits for loadA first, wasted time

Two consecutive awaits serialize the work — use Promise.all for independent tasks.

Gotcha

Using await inside a non-async function is a SyntaxError (except at the top level of an ES module). Awaiting sequentially on independent promises is a common performance bug — batch with Promise.all.

Related

← All JS Promise reference · async/await vs promises vs callbacks