Event Loop Basics (What Actually Runs When)
On this page
The Loop Concept
The event loop continuously checks for pending tasks and executes them when the call stack is empty.
Phases Overview
- Timers
- Pending Callbacks
- Poll
- Check
- Close Callbacks
Timer Example
setTimeout(() => console.log('timer'), 0);
console.log('sync');
Execution Order
Synchronous code runs first. Then queued callbacks execute according to loop phase rules.
Production Rule
Keep synchronous sections small to allow the loop to progress smoothly.