CodingNeed.
Mid · Concurrency

Explain the Event Loop

Predict the order of synchronous code, promise microtasks, and timers. Explain why a long-running callback can delay every timer.

Examples

Compare approaches

Baseline approach

Begin by explaining the core mechanism, stating assumptions, and walking through one concrete example.

Time: Depends on design · Space: Depends on design

console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
Strong answer

A, D, C, B. Current synchronous work finishes before microtasks drain; the timer callback is eligible afterward.

Time: Discuss operation costs · Space: Discuss retained state

console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");

Common traps

  • A zero-delay timer is not immediate.
  • State assumptions and justify trade-offs rather than memorizing a single answer.
Practise in the workspace →

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.