Skip to content

await

In one line

The await keyword pauses an async function until a promise settles, then resumes with the resolved value.

In simple words

await makes asynchronous code read like synchronous code. When you write const data = await fetch(url), the function pauses at that line until the promise from fetch settles, then resumes with the resolved value assigned to data.

await can only be used inside async functions (or at the top level in modern modules). If the awaited promise rejects, await throws the error, which you can catch with a regular try/catch block — no .catch() chaining needed.

While the function is paused at an await, the event loop is free to run other tasks. This is why await is non-blocking: your function waits, but the program does not. Other handlers, timers, and network responses keep running.

Example

javascript
async function loadUser() {
  try {
    const res = await fetch("/api/user");
    const user = await res.json();
    console.log(user);
  } catch (err) {
    console.error("Load failed:", err);
  }
}

await pauses until each promise settles. Errors are caught with a normal try/catch block.

Common confusions

  • Confused with: async

    The difference: await pauses execution inside an async function until a promise settles; async declares the function that allows await. You need async on the function to use await in its body.

Related terms

Related Resources

Related Lessons

Learn the fundamentals

Deepen your understanding with structured lessons on this topic.

View lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary