
“Explain the event loop” is one of the most asked JavaScript interview questions I’ve seen. It came up in some form in almost every loop I went through, either directly or hidden inside an “what does this code print?” puzzle.
Most explanations I read when I was preparing were either too shallow (“JavaScript is single-threaded and uses callbacks”) or went straight into the HTML spec. Here’s the version I wish I’d had: one diagram, the rules that actually matter, and the puzzles interviewers love.
The diagram

JavaScript runs on one main thread with one call stack. Things like timers, network requests, and DOM events are handled by the browser outside of JavaScript. When they’re ready, they don’t interrupt your code. They put a callback in a queue, and the event loop picks it up when the stack is empty.
The whole thing comes down to three rules.
Rule 1: Run one task to completion
A task (often called... premium content.
