JavaScript Event Loop — Concise Notes
Core Idea
The event loop is the runtime mechanism that allows JavaScript to handle asynchronous work without blocking the main thread.
JavaScript itself is single-threaded: it has one main call stack for executing code. The event loop coordinates the call stack, async runtime APIs, task queues, and callback execution.
One-Sentence Definition
The event loop is the orchestration system that decides when asynchronous callbacks are moved from queues back onto the call stack for execution.
Main Components
1. Call Stack
The call stack is where synchronous JavaScript code runs.
It works like a stack: