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

Promise chaining order

πŸ’‘

Hint

Returning a Promise from .then() adds 2 extra microtask ticks β€” it's slower than returning a plain value.

What does this output?

Promise.resolve()
  .then(() => {
    console.log(1);
    return Promise.resolve(2);
  })
  .then(v => console.log(v));

Promise.resolve()
  .then(() => console.log(3))
  .then(() => console.log(4));

Correct Output

1
3
4
2

Why this output?

Explanation: Round 1 microtasks: logs 1 (but returning a Promise adds extra ticks), logs 3.
Round 2: logs 4 (chained from 3). The inner Promise.resolve(2) takes 2 extra microtask ticks to unwrap.
Round 3+: logs 2 last.

Key Insight: Returning a Promise from .then() adds 2 extra microtask ticks β€” it's slower than returning a plain value.

More Event Loop & Promises Output Questions

🟑 MediumClassic setTimeout vs Promiseβ†’πŸ”΄ HardNested setTimeout and Promiseβ†’πŸŸ‘ Mediumasync/await execution orderβ†’πŸŸ‘ MediumPromise constructor is synchronousβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz