πŸ”΄ HardEvent Loop & PromisesπŸ’» Output Question

Multiple awaits

πŸ’‘

Hint

Each await is a suspension point β€” code after it resumes in a new microtask tick.

What does this output?

async function run() {
  console.log('A');
  await null;
  console.log('B');
  await null;
  console.log('C');
}

run();
console.log('D');

Correct Output

A
D
B
C

Why this output?

Explanation: "A" logs sync. First await suspends, "D" logs. Microtask 1 resumes: "B" logs. Second await suspends again. Microtask 2: "C" logs.

Key Insight: Each await is a suspension point β€” code after it resumes in a new microtask tick.

More Event Loop & Promises Output Questions

🟑 MediumClassic setTimeout vs Promiseβ†’πŸ”΄ HardNested setTimeout and Promiseβ†’πŸŸ‘ Mediumasync/await execution orderβ†’πŸ”΄ HardPromise chaining orderβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz