Explain the JavaScript Event Loop, Call Stack, Microtask, and Macrotask Queues
JavaScript is a single-threaded runtime with a non-blocking, asynchronous event-driven I/O model. It uses the Event Loop to orchestrate execution between synchronous operations ...
JavaScript is a single-threaded runtime with a non-blocking, asynchronous event-driven I/O model. It uses the Event Loop to orchestrate execution between synchronous operations and asynchronous callbacks.
1. Call Stack
Synchronous code executes sequentially in the Call Stack using a Last-In, First-Out (LIFO) order.
2. Microtask Queue
High-priority tasks such as Promise.then(), Promise.catch(), queueMicrotask(), and process.nextTick(). The event loop completely exhausts all microtasks before running any macrotasks.
3. Macrotask (Task) Queue
Asynchronous operations like setTimeout(), setInterval(), setImmediate(), and I/O callbacks.
Interviewer Evaluation Points & Scoring Rubric
- 1 Give a concise, high-level definition before diving into technical details.
- 2 Provide a concrete real-world production use case or code example.
- 3 Contrast with common alternatives or prior versions.