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

Understanding Sequential Await Execution

Learn how multiple await statements execute one after another, blocking subsequent operations until each completes.

Understanding Sequential Await Execution

You'll learn: How multiple await statements execute one after another, pausing execution until each promise resolves before moving to the next line.

The Core Idea

When you write multiple await statements in an async function, they execute sequentially — meaning each one blocks and waits for its promise to settle before the next line runs. This is fundamentally different from firing off multiple promises at once.

Think of it like a queue at a coffee shop where only one person can order at a time. Each customer must complete their order before the next person steps up. Similarly, each await must finish before the next one begins.

How It Works in Practice

async function fetchUserData() {
  console.log('Starting...');
  
  const user = await fetchUser(userId);      // Waits here
  console.log('User fetched');
  
  const posts = await fetchPosts(user.id);   // Waits here
  console.log('Posts fetched');
  
  const comments = await fetchComments(posts[0].id); // Waits here
  console.log('Comments fetched');
  
  return comments;
}

The execution order is strictly linear:

  1. fetchUser() starts and JavaScript pauses at that line
  2. Once the user promise resolves, fetchPosts() starts
  3. Only after posts resolve does fetchComments() begin
  4. Each operation waits for the previous one to complete

This is intentional blocking behavior. If fetchPosts() needs data from fetchUser(), sequential execution makes perfect sense. However, if the operations are independent, this approach is slower than necessary — they could run concurrently.

Key Takeaway: Multiple await statements execute one at a time in order, with each blocking subsequent code until its promise settles — choose this pattern when later operations depend on earlier results.