Skip to content
Preptima
mediumCodingConceptMidSenior

Here is a script mixing setTimeout, a promise chain and an await. Tell me the order the logs come out in, and why.

4 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

The engine finishes the current task, then drains the whole microtask queue before taking another task, so every promise callback and await resumption runs before a zero-delay timeout, in the order each was queued.

Was this answer helpful?

Likely follow-ups

  • How would you process fifty thousand items without freezing the page, and what do you yield with?
  • Where do requestAnimationFrame callbacks fall relative to the microtask queue?
  • A test passes when you await a resolved promise twice and fails when you do it once. What does that tell you about the code under test?
  • Why does a chain of zero-delay timeouts run more slowly than you would expect?

Related questions

Further reading