🟑 MediumEvent Loop & PromisesπŸ’» Output Question

Promise constructor is synchronous

πŸ’‘

Hint

The Promise executor is synchronous. Only .then() callbacks are async (microtasks).

What does this output?

console.log('1');

new Promise((resolve) => {
  console.log('2');
  resolve();
  console.log('3');
}).then(() => console.log('4'));

console.log('5');

Correct Output

1
2
3
5
4

Why this output?

Explanation: The Promise executor function runs synchronously. resolve() schedules the .then callback as a microtask but does NOT stop execution. "3" still prints before "5".

Key Insight: The Promise executor is synchronous. Only .then() callbacks are async (microtasks).

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