In a code review you see a function that logs A, schedules a setTimeout(...,0) that logs B, and resolves a Promise that logs C, all before logging D synchronously. A teammate expects the order A, B, C, D. Walk me through the actual order and why.

technical-conceptual · Senior level · software-engineering

What the interviewer is really asking

Tests genuine understanding of the event loop, the microtask-versus-macrotask distinction, and the ordering guarantees that cause real async timing bugs.

What to say

What to avoid

Example answers

Strong: The synchronous lines run first, so A then D. When the stack clears, microtasks drain before any macrotask, so the resolved Promise's C runs next. The setTimeout callback is a macrotask, so B runs last. Final order: A, D, C, B. The teammate's mental model misses that promises are microtasks and jump ahead of timers.

Weak: Both setTimeout and the Promise are async, so they run after the synchronous code, but between the two the order isn't really guaranteed, it depends on the engine. So roughly A, D, then B and C in whatever order they land.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.