Learn JavaScript
❯ getting_started.engines

Engines, JIT & the Event Loop (Overview) in JavaScript

$concept

JavaScript runs on engines — V8 (Chrome, Node), SpiderMonkey (Firefox), JavaScriptCore (Safari) — that parse source and Just-In-Time compile hot code to machine code, optimizing and deoptimizing as types change under them. You never invoke the compiler yourself; it lives inside the runtime.

Execution centers on the event loop: one call stack runs your code while async results (timers, network, I/O) queue as tasks, processed when the stack empties. This single-threaded model is why long synchronous loops freeze pages — and why async patterns exist. Full detail arrives in the Async module; this is the mental model to carry there.

$how it works
1

Engines compile invisibly

V8 and friends parse your source and JIT-compile hot paths — deployment is still just shipping text files.

2

One call stack

Functions nest on a single stack; it must empty before anything else (timers, clicks, fetches) gets handled.

3

Tasks queue behind it

Async completions wait in task/microtask queues until the stack clears — ordering guarantees flow from this, covered in Async.

4

Blocking freezes everything

A 3-second synchronous loop blocks rendering, input, and timers alike — the cardinal sin async code exists to avoid.

$example
console.log("first");
setTimeout(() => console.log("third"), 0);
console.log("second");
Output
first
second
third
1first prints immediately — synchronous code runs straight through.
2setTimeout with 0ms doesn't run now — it queues a task behind the current stack.
3second prints, the stack empties, then the queued task prints third — event-loop ordering in three lines.
$use cases
Understanding why zero-delay timers still run after synchronous code
Diagnosing frozen pages as blocked-stack problems
Trusting engines to optimize hot code without manual hints
Carrying this mental model into promises and async/await later

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.