Explain how the JavaScript Event Loop prioritizes synchronous code, Promise callbacks, and `setTimeout(..., 0)`.
What happens to UI rendering if a recursive Promise microtask chain keeps scheduling new microtasks endlessly?
What the Rubric Checks
- • Traces Call Stack -> Microtask Queue (Promises, queueMicrotask) -> Macrotask Queue (setTimeout, I/O)
- • Explains that the microtask queue drains completely before the next paint/macrotask
- • Identifies UI starvation risk
High-Scoring Answer Blueprint
Synchronous code runs on the call stack to completion first. Next, the event loop drains the entire microtask queue (Promise `.then`/`.catch`, `queueMicrotask`) before picking a single macrotask (`setTimeout`, DOM events) or letting the browser repaint. Infinite microtasks therefore starve rendering and freeze the tab.