Predict the Event Loop

Talk it through out loud with your AI coach.

The problem

  • medium
  • Pro

A script does four things in this order: it logs A; it schedules a timeout with zero delay that logs B; it creates an already-resolved promise whose then callback logs C; and it logs D. Say in what order the letters are printed, and explain why using the call stack, the task queue and the microtask queue.

What a strong answer covers

  • The order the four logs appear in.
  • Why plain synchronous code always finishes before any callback.
  • How promise callbacks and timer callbacks are queued differently.
  • Why a zero-millisecond delay doesn't mean 'run immediately'.

Common mistake: Assuming a zero-delay timer runs before a resolved promise's callback because it was scheduled first.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud