cf.completefrontendCode editorOpen lab
THE JAVASCRIPT FIELD GUIDE

Engines, runtimes & hosts

Learn how the JavaScript engine that runs the language differs from the browser, server runtime, or host APIs around it.

By the end, you'll know
  • 01
    The engine's jobName V8, SpiderMonkey, and JavaScriptCore and what they run.
  • 02
    The host's jobSeparate JavaScript syntax from browser, Node.js, Deno, and Bun APIs.
  • 03
    One 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 short version

The engine runs JavaScript. The host gives JavaScript somewhere to live and extra APIs to talk to the outside world.

Real-life analogyChef and kitchen

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, and localStorage
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 IT

An 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.

Common JavaScript engines and where you meet them
EngineWhere you usually see itCareful wording
V8Chrome, Edge, Opera, Node.js, and DenoChromium-based browsers and several server runtimes use V8.
SpiderMonkeyFirefoxMozilla's browser engine for JavaScript.
JavaScriptCoreSafari and BunSafari uses JavaScriptCore. Bun also uses JavaScriptCore.
WebKit on iPhone/iPadHistorically all iOS/iPadOS browsersFor most of iOS's history, browsers on iPhone and iPad were required to use WebKit, whose JavaScript engine is JavaScriptCore.
Real-life analogyCar engine, different bodies

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

INTERACTIVE

A 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.

Which host am I in?
Browser host probePop out in the code editor (opens in a new tab)JavaScript
const info = {  window: typeof window,  document: typeof document,  process: typeof process,  globalThis: typeof globalThis,  userAgent: navigator.userAgent,};console.table(info);
Real resultnot yet
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

Try it yourself

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 the browser's user agent string, which can be incomplete or intentionally misleading. Treat it as a clue, not proof.

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.”

Deno and Bun in one breath

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 IT

When 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.

Language feature or host API?
  • Array.prototype.map
  • JSON.parse
  • Math.max
  • Promise
  • document.querySelector
  • localStorage
  • fetch
  • alert
  • process.argv
  • require('fs')
  • setTimeout
  • console.log
Try it yourself
0 of 12 correct

Sort each name by who provides it. Read the explanation after each card; several answers are deliberately close.

Choose a category for every card. You can change an answer at any time; Reset clears them all.
How to ask the right compatibility question
If you see...Ask...Example
Syntax or built-insIs this JavaScript language support?Array.prototype.map, JSON.parse, Promise
A page, storage, dialog, or network objectDoes this host provide that API?document, localStorage, alert, fetch
Files, command-line arguments, packagesWhich server runtime is this for?process.argv, require('fs')
A name available in several placesIs 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.

One script, one function call
Step 0 of 8Ready
Your turn: follow the blue line

Predict the printed sentence. Then step through how the script calls one function and returns to the script.

Running in
  1. script
Next: line 1
Click the blue line to take the next stepPop out in the code editor (opens in a new tab)JavaScript
function describeHost(place) {  const kitchen = place + " host";  return "JavaScript running in a " + kitchen;}const summary = describeHost(host);console.log(summary);
CallStoreChangeResultRun = next line. Ran = already executed.
Recent returnsNothing yet. Start with the blue line.
Change line 1, then predict line 7

The function call order is the same. Only the value passed into the function changes.

A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

Single-threaded by design

REAL FREEZE

JavaScript 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.

Real-life analogyOne cashier, one line

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.

Main thread freeze test
Main-thread demoPop out in the code editor (opens in a new tab)JavaScript
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();}
Animated counteridle
0

Try clicking another button while blocking work is running. The click waits until the busy loop finishes.

Try it yourself

The counter uses requestAnimationFrame. Try the blocking button, then the chunked button.

Both buttons do about the same total busy work. The first monopolizes the main thread; the second yields between slices with setTimeout. The duration is capped to keep the demo safe.

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?”
A tiny debugging checklist

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 EXERCISES
Exercise 1 · Warm-upAsk your browser what exists

Open the browser console and run typeof window. Type what it prints.

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · PracticeCompare process

    Run typeof process in your browser console. Optionally try it in Node in the next lesson after setup.

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticePredict synchronous order

      Without running it, predict the three console lines.

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      console.log("A");
      function run() {
        console.log("B");
      }
      run();
      console.log("C");

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeFind your engine

        Use the engine table and the host experiment to identify the likely engine for your browser.

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeSort four APIs

          Use the sorter rules. Which category gets process.argv?

          Starter codePop out in the code editor (opens in a new tab)JavaScript
          Array.prototype.map -> language
          process.argv -> Node host
          document.querySelector -> browser host
          setTimeout -> shared host API

          Answer, then press Check. Spacing and letter case don’t matter.

            Quiz: engines, runtimes & hosts

            7 QUESTIONS

            Check the model. Every answer explains why it is right or wrong.

            Lesson quiz · 7 questionsScore: first tries count
            1. Question 1 of 7What is a JavaScript engine responsible for?

              Choose an answer to see the explanation.

            2. Question 2 of 7Which engine is used by Firefox?

              Choose an answer to see the explanation.

            3. Question 3 of 7What does this global check print?

              Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
              console.log(typeof globalThis);

              Choose an answer to see the explanation.

            4. Question 4 of 7Which item is a browser host API rather than a language feature?

              Choose an answer to see the explanation.

            5. Question 5 of 7What does this print in a normal browser page?

              Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
              console.log(typeof process);

              Choose an answer to see the explanation.

            6. Question 6 of 7Why does a 1.5 second busy loop freeze the animated counter?

              Choose an answer to see the explanation.

            7. Question 7 of 7What is the synchronous log order?

              Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
              console.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, and Promise are different from host APIs such as document, 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.

            CompleteFrontend Clear concepts. Working examples.