Engines, runtimes & hosts
Learn how the JavaScript engine that runs the language differs from the browser, server runtime, or host APIs around it.
- 01The engine's jobName V8, SpiderMonkey, and JavaScriptCore and what they run.
- 02The host's jobSeparate JavaScript syntax from browser, Node.js, Deno, and Bun APIs.
- 03One main threadSee why long synchronous work freezes a page and how small chunks keep it responsive.
One program, three layers around it
JavaScript can feel mysterious because people use the same word for several things. They say “JavaScript runs in Chrome,” “JavaScript runs in Node,” and “JavaScript has document.querySelector.” Those sentences point at different layers.
The engine is the part that understands the JavaScript language: variables, functions, arrays, objects, JSON.parse, Promise, and the rules from the ECMAScript standard. The host is the larger program around that engine: a browser tab, Node.js, Deno, Bun, or another environment. The host gives your code extra powers such as a page to change, files to read, timers to schedule, or a console to print to.
The engine runs JavaScript. The host gives JavaScript somewhere to live and extra APIs to talk to the outside world.
Imagine a chef who can cook any recipe written in JavaScript. Put that chef in a browser kitchen and they can reach for the web page, storage, and browser dialogs. Put the same chef in a server kitchen and they can reach for files, command-line arguments, and server connections. The cooking knowledge is the engine; the kitchen tools are the host.
- In real life: The chef who knows recipes
- In JavaScript: The JavaScript engine that knows the language
- In real life: A browser kitchen with a menu board and serving window
- In JavaScript: Browser APIs like
document,fetch, andlocalStorage - In real life: A server kitchen with a pantry and order printer
- In JavaScript: Node APIs like
fs,process, and server networking - In real life: The same recipe cooked in different kitchens
- In JavaScript: The same JavaScript syntax running in different hosts
Where the analogy stops: A real chef can use judgment when a kitchen is missing a tool. JavaScript cannot: if the host does not provide document, code that uses document throws an error.
This lesson connects the history you just learned to the practical setup coming next. You will not install anything here; the next lesson, Setting up your tools, handles that. Today, your browser itself is enough.
V8, SpiderMonkey & JavaScriptCore
MAP ITAn engine is an implementation of the JavaScript language. It reads your source code, checks that the syntax makes sense, creates values and functions, runs statements, and returns results. Different browser makers build different engines, but they aim at the same ECMAScript standard from the previous lesson.
| Engine | Where you usually see it | Careful wording |
|---|---|---|
| V8 | Chrome, Edge, Opera, Node.js, and Deno | Chromium-based browsers and several server runtimes use V8. |
| SpiderMonkey | Firefox | Mozilla's browser engine for JavaScript. |
| JavaScriptCore | Safari and Bun | Safari uses JavaScriptCore. Bun also uses JavaScriptCore. |
| WebKit on iPhone/iPad | Historically all iOS/iPadOS browsers | For most of iOS's history, browsers on iPhone and iPad were required to use WebKit, whose JavaScript engine is JavaScriptCore. |
A car engine does not decide whether the car has two seats, a big trunk, or a roof rack. It provides power inside a larger vehicle. V8 inside Chrome and V8 inside Node.js are similar in that way: the engine is related, but the body around it gives different abilities.
- In real life: A car engine turns fuel into motion
- In JavaScript: A JavaScript engine turns source code into running behavior
- In real life: The body might be a van, sports car, or truck
- In JavaScript: The host might be Chrome, Node.js, Deno, Bun, or Safari
- In real life: The same engine can appear in several models
- In JavaScript: V8 appears in Chrome and Node.js
Where the analogy stops: Car engines are physical objects you can see. JavaScript engines are software, and hosts also include many other pieces such as rendering, security, networking, and developer tools.
Engine names matter when you read release notes, debug compatibility, or hear that a runtime is “built on V8.” They do not mean you must write three different versions of ordinary JavaScript. For beginner code, the language features are shared far more often than they differ.
Browsers vs Node.js, Deno & Bun
INTERACTIVEA browser host gives JavaScript a page and browser features: window, document, localStorage, alert, and many web APIs. A server runtime host gives JavaScript server features: command-line arguments, file access, environment variables, and tools for running programs outside a page.
The clearest proof is to ask the host what globals exist. Run this experiment in your real browser. Notice especially that window and document exist here, while process normally belongs to Node.js. globalThis is the standard name that works across modern hosts.
const info = { window: typeof window, document: typeof document, process: typeof process, globalThis: typeof globalThis, userAgent: navigator.userAgent,};console.table(info);- typeof window
- not checked yet
- typeof document
- not checked yet
- typeof process
- not checked yet
- typeof globalThis
- not checked yet
Engine guess: Click Run check to ask this browser.
User agent: waiting for the browser
This code runs in your current browser. It found window=not checked yet, document=not checked yet, process=not checked yet, globalThis=not checked yet.
The engine guess uses navigator.userAgent, a string the browser reports about itself. It is useful for a friendly clue, not a courtroom witness: user agents can be shortened, frozen, or spoofed. The reliable lesson is not “trust this exact string”; it is “the same language runs inside different hosts.”
Node.js, Deno, and Bun are runtimes: programs you can install to run JavaScript outside a browser. Node.js and Deno use V8. Bun uses JavaScriptCore. Each adds its own command-line tools and host APIs.
Language features vs host APIs
SORT ITWhen code “works in JavaScript,” ask a sharper question: is this part of the language, or did a host provide it? Language features travel with JavaScript itself. Host APIs depend on where the code runs.
Array.prototype.mapJSON.parseMath.maxPromisedocument.querySelectorlocalStoragefetchalertprocess.argvrequire('fs')setTimeoutconsole.log
Sort each name by who provides it. Read the explanation after each card; several answers are deliberately close.
| If you see... | Ask... | Example |
|---|---|---|
| Syntax or built-ins | Is this JavaScript language support? | Array.prototype.map, JSON.parse, Promise |
| A page, storage, dialog, or network object | Does this host provide that API? | document, localStorage, alert, fetch |
| Files, command-line arguments, packages | Which server runtime is this for? | process.argv, require('fs') |
| A name available in several places | Is it shared by hosts, or standardized separately? | console, setTimeout, and often fetch |
This distinction prevents a common beginner frustration. Array.prototype.map works in Node and in a browser because arrays are language values. document.querySelector works in a browser because the browser gives you a document. Try the same line in plain Node.js and there is no page to query.
Predict the printed sentence. Then step through how the script calls one function and returns to the script.
script
function describeHost(place) { const kitchen = place + " host"; return "JavaScript running in a " + kitchen;}const summary = describeHost(host);console.log(summary);Single-threaded by design
REAL FREEZEJavaScript code in a browser tab normally runs on one main thread: one path of execution that does one thing at a time. The host can have other helper threads behind the scenes, but your ordinary script statements do not all run at once. A function call pauses the surrounding script, runs the function, then returns.
Picture one cashier at a small shop. If one customer asks for a giant, complicated order, everyone waits. If the cashier handles it in small pieces and lets quick customers through between pieces, the line feels alive again. Long JavaScript work on the main thread has the same effect.
- In real life: One cashier serves one customer at a time
- In JavaScript: The main thread runs one JavaScript task at a time
- In real life: A huge order blocks the people behind it
- In JavaScript: A long loop blocks clicks and repainting
- In real life: Breaking an order into pickups lets others move
- In JavaScript: Chunking work with timers gives the host turns between slices
Where the analogy stops: Real stores can add another cashier. Browser JavaScript can use advanced tools like workers, but ordinary page code still needs you to avoid blocking the main thread.
Try the demo. The counter is driven by the host asking the page to repaint. The blocking button runs a tight loop for about 1.5 seconds. During that loop, the counter and clicks freeze. The chunked button does about the same total busy work in small slices with setTimeout, so the host gets chances to repaint between slices.
let frame = 0;function tick() { frame = frame + 1; requestAnimationFrame(tick);} function blockFor(milliseconds) { const end = performance.now() + milliseconds; while (performance.now() < end) { // Busy work keeps the main thread occupied. }} function chunkedWork(milliseconds) { const end = performance.now() + milliseconds; function slice() { const sliceEnd = Math.min(performance.now() + 25, end); while (performance.now() < sliceEnd) {} if (performance.now() < end) setTimeout(slice, 0); } slice();}Try clicking another button while blocking work is running. The click waits until the busy loop finishes.
The counter uses requestAnimationFrame. Try the blocking button, then the chunked button.
This is not the full event loop lesson. Later, The event loop will explain tasks, callbacks, and scheduling in depth. For now, remember the beginner rule: while your synchronous JavaScript is running, the main thread cannot do something else for your page.
Where you’ll use this
This mental model turns confusing errors into useful clues. If the console says document is not defined, you probably ran browser code in a server host. If it says process is not defined, you probably ran Node-specific code in a browser. If an older browser does not understand a new method, you are dealing with language or API compatibility rather than a typo.
- When reading MDN, check whether a page describes a JavaScript language feature or a Web API.
- When choosing a package, check whether it expects Node APIs, browser APIs, or both.
- When a page feels frozen, look for long synchronous work on the main thread.
- When comparing Node.js, Deno, and Bun, ask both “which engine?” and “which host APIs?”
Before blaming “JavaScript,” ask: is the language feature supported, is the host API present, and am I blocking the main thread? Those three questions solve many beginner mysteries.
Common misconceptions
“V8 is JavaScript.”
V8 is one engine that runs JavaScript. JavaScript is the language; engines are implementations.
“Node.js and the browser are basically the same.”
They can run much of the same language code, but their host APIs differ. Browsers have a page; Node has server and file-system tools.
“If Chrome has it, JavaScript has it.”
Chrome includes JavaScript plus Web APIs. Some names you use in Chrome, like document, come from the browser host.
“Single-threaded means slow.”
It means one task runs at a time on the main thread. Fast tasks are fine. Long blocking tasks are the problem.
“setTimeout makes work parallel.”
Timers schedule later work. They can split work into slices, but the slices still run one at a time on the main thread.
Practice: spot the layer
5 EXERCISESOpen the browser console and run typeof window. Type what it prints.
In a normal browser page, typeof window prints object because the browser host provides window. In non-browser hosts it may be undefined.
processRun typeof process in your browser console. Optionally try it in Node in the next lesson after setup.
In a normal browser page, typeof process is usually undefined. In Node.js, process is a host object, so the type is object.
Without running it, predict the three console lines.
console.log("A");
function run() {
console.log("B");
}
run();
console.log("C");Line 1 prints A. The call to run() enters the function and prints B. Then control returns to the script and line 5 prints C.
Use the engine table and the host experiment to identify the likely engine for your browser.
Use the browser family to choose an engine name: V8 for Chromium-based browsers, SpiderMonkey for Firefox, JavaScriptCore for Safari. Remember that the user agent is a clue, not perfect proof.
Use the sorter rules. Which category gets process.argv?
Array.prototype.map -> language
process.argv -> Node host
document.querySelector -> browser host
setTimeout -> shared host APIArray.prototype.map -> language
process.argv -> Node host
document.querySelector -> browser host
setTimeout -> shared host APIArray.prototype.map is language. process.argv is Node host. document.querySelector is browser host. setTimeout is a host timer found in browsers and Node.
Quiz: engines, runtimes & hosts
7 QUESTIONSCheck the model. Every answer explains why it is right or wrong.
Question 1 of 7What is a JavaScript engine responsible for?
Choose an answer to see the explanation.
Question 2 of 7Which engine is used by Firefox?
Choose an answer to see the explanation.
Question 3 of 7What does this global check print?
Read the code, then predictconsole.log(typeof globalThis);Choose an answer to see the explanation.
Question 4 of 7Which item is a browser host API rather than a language feature?
Choose an answer to see the explanation.
Question 5 of 7What does this print in a normal browser page?
Read the code, then predictconsole.log(typeof process);Choose an answer to see the explanation.
Question 6 of 7Why does a 1.5 second busy loop freeze the animated counter?
Choose an answer to see the explanation.
Question 7 of 7What is the synchronous log order?
Read the code, then predictconsole.log("start"); function label() { console.log("inside"); } label(); console.log("end");Choose an answer to see the explanation.
Key takeaways
- V8, SpiderMonkey, and JavaScriptCore are engines: software that runs the JavaScript language.
- Browsers, Node.js, Deno, and Bun are hosts or runtimes: they embed an engine and add APIs.
- Language features such as arrays,
JSON,Math, andPromiseare different from host APIs such asdocument,process, timers, and storage. - Ordinary JavaScript on a page runs one main-thread task at a time. Long synchronous work freezes the interface.
- When code fails, ask whether you used the wrong host, an unsupported feature, or a blocking chunk of work.
Remember the one-liner.
The engine runs the language; the host provides the world around it.
Up next: Setting up your tools.