Skip to content
RED SAGSkills
mediumFrontend Developer interview question

Explain the JavaScript event loop, including microtasks and macrotasks.

What the interviewer wants to hear

  • JavaScript runs on a single main thread with a call stack
  • Async work is handled by browser APIs and queued callbacks
  • Microtasks (promises, queueMicrotask) run after each task, fully drained
  • Macrotasks (setTimeout, events, I/O) run one per loop turn
  • Rendering happens between tasks; long tasks block the UI

Model answer

JavaScript in the browser runs on one main thread with a call stack. When code calls something async, like setTimeout or fetch, the browser handles the waiting and later puts a callback in a queue. The event loop takes one task from the task queue, runs it until the stack is empty, then drains the whole microtask queue, which holds promise callbacks and queueMicrotask callbacks. After that the browser may render a frame, and then it picks the next task. This is why a resolved promise callback runs before a setTimeout of 0. It also means a long synchronous task, or an endless chain of microtasks, blocks rendering and clicks, which hurts INP. I split heavy work into chunks or move it to a Web Worker.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Frontend Developer questions