What is a JavaScript engine? Examples?
Executes JS code. Examples: V8, SpiderMonkey, JavaScriptCore, Chakra.
Three types of Execution Contexts?
Global, Function, Eval.
What is the Global Execution Context?
Base context created first. In browsers, associated with window/globalThis.
What is the Call Stack?
LIFO structure tracking active execution contexts.
What happens if Call Stack is too large?
Stack Overflow error, often from infinite recursion.
What is the Event Loop?
Mechanism for async operations, monitors call stack and task queue.
What are Microtasks?
High-priority tasks after each macrotask. Examples: Promise .then, queueMicrotask.
What are Macrotasks?
Executed after microtasks. Examples: setTimeout, setInterval, I/O.
How does async code run in JS?
Offloaded to APIs, callback queued, event loop pushes to call stack when clear.
What is the Task Queue?
Holds callbacks awaiting execution, processed by event loop.
Difference between Stack and Heap?
Stack: static memory (primitives, calls).
Heap: dynamic memory (objects, arrays).