Q13: What is the JavaScript Event Loop?
The Event Loop enables non-blocking asynchronous execution. JavaScript executes synchronous code on the single Call Stack. Asynchronous tasks offload to APIs and queue callbacks into the Microtask Queue (Promises) or Macrotask Queue (timers). The Event Loop empties the call stack, drains all microtasks, and then processes one macrotask.
Key Takeaways
- Call stack processes synchronous tasks sequentially.
- Microtasks (Promises) take execution priority over Macrotasks (setTimeout).
Knowledge Check
Which queue has higher execution priority: Microtask or Macrotask Queue?