Episode 1 — Fundamentals / 1.13 — Introduction to JavaScript
1.13.b — Where JavaScript Runs
In one sentence: JavaScript is one language with multiple runtimes — most often the browser (with DOM and Web APIs) or Node.js (with files, networking, and no
window/documentby default).
Navigation: ← 1.13.a — What is JavaScript? · 1.13.c — Linking JS with HTML →
1. Browser JavaScript
When JS runs in a web page, the host is the browser. You typically have:
| Capability | Examples |
|---|---|
| DOM | document.querySelector, creating elements, reading form values |
| Web APIs | fetch, localStorage, setTimeout, addEventListener |
| Globals | window, document, console |
Security model: Code from one origin is isolated from others (same-origin policy for many APIs). User-triggered actions and permissions (camera, location) are gated for safety.
Use cases: Interactive UIs, client-side validation, SPAs, progressive enhancement on top of HTML/CSS.
2. Node.js
Node.js is a JavaScript runtime built on Chrome’s V8 engine, designed for servers, CLIs, and tooling. It does not include the browser DOM.
| Capability | Examples |
|---|---|
| File system | Reading/writing files (fs module) |
| HTTP | Building APIs, proxy servers |
| Process | Environment variables, process.argv for CLI args |
| Tooling | Running tests, bundlers (Vite, webpack), formatters |
Globals differ: No window or document. You have global / globalThis, process, Buffer (in many setups), and CommonJS require or ES modules import depending on project config.
Use cases: REST/GraphQL backends, static site generation, build scripts, desktop tooling (e.g. with Electron — which does embed a browser for UI).
3. Same language, different environments
Your .js file
│
├──► Browser: V8 / SpiderMonkey / JSC + DOM + Web APIs
│
└──► Node.js: V8 + libuv (I/O) + Node core modules
Core syntax (if, for, function, const) is the same. What changes is which objects and modules exist at runtime.
4. ECMAScript (ES)
The language specification is called ECMAScript (e.g. ES2015, ES2020). Engines and Node implement that spec plus host-specific APIs. When people say "JavaScript," they usually mean ECMAScript + host APIs.
5. Key takeaways
- Browser JS = DOM + Web APIs +
window/document. - Node.js = server/tooling runtime; no DOM unless you embed a browser (e.g. Puppeteer).
- Learn core JS once; learn environment APIs where you deploy.
Explain-It Challenge
Explain without notes:
- Name three things you can do in a browser with JS that you typically cannot do in plain Node without extra libraries.
- Why does
document.bodythrow or fail in a normal Node script? - What does it mean that Node uses the V8 engine?
Navigation: ← 1.13.a — What is JavaScript? · 1.13.c — Linking JS with HTML →