Explain Event Loop mechanics, detailing how microtasks and macrotasks are prioritized.
expand_more
.then, .catch), queueMicrotask callbacks, and MutationObserver callbacks. This queue must be *entirely emptied* before the Event Loop moves to the next phase, even if new microtasks are appended during execution.
2. Rendering Pipeline: The browser updates styles, layouts, and paints if appropriate.
3. Macrotasks Queue (or simply Task Queue): Contains setTimeout, setInterval, setImmediate (Node.js), and user interactions. Only *one macrotask* is executed per tick, after which the loop immediately checks the microtasks queue again.
Understanding this is critical to avoid UI starvation bugs caused by recursive microtask creation.