THN Interview Prep

JavaScript runtime model (browser & V8)

Core details

Single main thread per realm (typical tab or Node worker): call stack runs synchronous code; async work completes later on queues.

PieceRole
Call stackcurrently executing functions
Heapobjects (GC-managed)
Web APIs / libuvtimers, network, I/O callbacks scheduled
Task queuesmacrotasks (e.g. timer, I/O completion)
Microtask queuePromise.then, queueMicrotask—runs after stack clears, before next macrotask

Event loop (browser sketch): process microtasks until empty → take one macrotask → repeat → render when needed.

Node: similar loop with phases (timers, poll, check for setImmediate); process.nextTick runs before other microtasks—easy to starve I/O if abused.

Understanding

Closure = function + captured env; hoisting = var/function decl creation before execution per scope rules (let/const TDZ different).

Interview line:await yields the function; microtasks chain before the next timer callback.”

Senior understanding

TrapNarrative
CPU-bound on main threadchunk work or Worker—async doesn’t parallelize CPU
Mass nextTickcan block I/O phase

Diagram

Loading diagram…

See also

Last updated on

Spotted something unclear or wrong on this page?

On this page