Course contentsShow
← JavaScript
Lesson 1342 of 2,72330. Async/AwaitFree lesson

What Await Does

The await keyword pauses async function execution until a promise settles, returning its resolved value.

What Await Does

You'll learn: How await pauses execution in an async function until a promise resolves, giving you its value directly.

The Core Idea

The await keyword is your way of saying "stop here and wait for this promise to finish." When JavaScript encounters await inside an async function, it pauses that function's execution until the promise settles. Once the promise resolves, await extracts and returns the resolved value—no .then() needed.

Think of it like waiting in line at a coffee shop. When you say await getCoffee(), you're standing at the counter until your order is ready. The barista hands you the actual coffee (the resolved value), not a receipt promising coffee (the promise object). Meanwhile, the rest of the coffee shop keeps operating—JavaScript doesn't freeze the entire program, just your spot in line.

How It Works in Practice

When you write const result = await somePromise, JavaScript:

  1. Pauses execution of the async function at that line
  2. Waits for somePromise to settle
  3. If resolved: extracts the value and assigns it to result
  4. If rejected: throws an error (which you can catch with try/catch)
  5. Resumes execution on the next line

This transforms promise-based code into something that reads sequentially, like synchronous code, even though it's still asynchronous under the hood.

Why This Matters

Without await, you'd work with the promise object itself and chain .then() calls. With await, you work directly with the values, making your code cleaner and easier to reason about.

Key Takeaway: await pauses an async function until a promise settles, then unwraps and returns the resolved value, letting you write asynchronous code that reads like synchronous code.