Event Loop in Depth

The Full Picture

PartRole
Call stackruns JavaScript, one frame at a time
Web APIs / libuvtimers, network and I/O done outside the JS thread
Microtask queuepromise reactions; drained completely after each task
Task queuetimers, events, I/O callbacks; one per loop turn
Renderingin browsers: style, layout and paint between tasks (~every 16 ms)

Blocking the Main Thread

Example

Long synchronous work delays everything else, including timers that are already due:

const start = Date.now();
setTimeout(() => console.log("timer ran after ~" + Math.round((Date.now() - start) / 100) * 100 + " ms (asked for 0)"), 0);
while (Date.now() - start < 300) {}   // busy loop blocks the thread
console.log("busy work done");

Output

busy work done
timer ran after ~300 ms (asked for 0)

Tip: Split heavy work into chunks, or move it to a Web Worker (browser) / worker thread (Node) so the UI stays responsive.