Frontend: Explain the JavaScript Event Loop

Contrast how microtasks, macrotasks, and rendering queues are ordered and processed by the engine.

Technical Reference & Key Concepts

The Challenge: Explain the Event Loop

An interviewer asks you to trace the execution order of synchronous code, promises, setTimeout, and requestAnimationFrame.

Core questions to address:

  1. What is the difference in execution priority between a Promise callback (microtask) and a setTimeout callback (macrotask)?
  2. In what phase of the loop is the DOM rendering queue executed?
  3. What happens if a microtask recursively schedules another microtask?