The Event Loop and Call Stack
How JavaScript's single-threaded call stack cooperates with the event loop, task queue, and microtask queue to handle asynchronous work.
JavaScript is single-threaded, meaning it can only execute one piece of code at a time on the call stack, yet it clearly handles timers, network requests, and user interactions without freezing the page. The event loop is the mechanism that makes this possible, and it is one of the most tested conceptual topics in JS interviews because it requires connecting several moving parts into one coherent mental model.
Think of the call stack as a single cashier who can only serve one customer at a time. The microtask queue is VIP customers who get served completely before the cashier looks at the regular line (macrotask queue) again — even if a VIP walks in while another VIP is already being helped.