MediumEvent Loop & Promises💻 Output Question

await suspends function — caller continues

💡

Hint

await suspends the async function. The caller continues synchronously. The resumed code runs as a microtask.

What does this output?

console.log('1');
async function main() {
  console.log('2');
  await Promise.resolve();
  console.log('3');
}
main();
console.log('4');

Correct Output

1
2
4
3

Why this output?

Explanation: 1 logs. main() starts, logs 2. await suspends main (schedules resume as microtask). 4 logs. Then microtask runs: 3 logs.

Key Insight: await suspends the async function. The caller continues synchronously. The resumed code runs as a microtask.

More Event Loop & Promises Output Questions

EasySynchronous code runs before setTimeoutMediumPromise microtask before setTimeout macrotaskMediumPromise chain passes valuesHardTwo Promise chains interleave in microtask queue

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz