Event Loop
Pronunciationih-VENT LOOP
Definition
The event loop is the mechanism that lets a single thread handle many tasks: it repeatedly takes the next waiting callback (a timer, a click, a network response) and runs it when the call stack is empty.
Where you hear it
In JavaScript and Node.js (and Python asyncio) interviews, performance debugging when the UI freezes and "why did setTimeout run last?" questions.
Examples
A long loop blocks the event loop, so the page can't respond.
setTimeout(fn, 0)still waits until the stack is empty.A slow loop in the handler froze the page because the event loop had no time to run.
Common mistake
Running heavy CPU work on the loop. Nothing else, including other users' requests in Node, can run meanwhile.
Don't confuse with
Multithreading, where several threads run at once. The event loop is one thread taking turns.
Say it at work
- In a meeting or chat
Don't block the event loop.
- In an email or ticket
Move the heavy work to a worker.
Keep exploring
More in Programming Fundamentals