🟑 MediumEvent Loop & PromisesπŸ’» Output Question

Promise.all ordering

πŸ’‘

Hint

Promise.all result order matches INPUT order, not resolution order.

What does this output?

async function delay(ms, val) {
  await new Promise(r => setTimeout(r, ms));
  return val;
}

const [a, b, c] = await Promise.all([
  delay(300, 'slow'),
  delay(100, 'fast'),
  delay(200, 'medium')
]);

console.log(a, b, c);

Correct Output

slow fast medium

Why this output?

Explanation: Promise.all preserves the order of results matching the input array β€” regardless of which resolves first. "fast" finishes first but appears second in results.

Key Insight: Promise.all result order matches INPUT order, not resolution order.

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