JavaScript is one language with two major runtimes. Syntax overlaps (functions, classes, async/await), but globals, APIs, and security boundaries differ sharply.
Browser-only
document,window, DOM APIs,fetch(also in modern Node)- Sandboxed—no raw file system or arbitrary shell (without extensions)
- User-controlled environment—never trust client code for secrets
Node-only
process,__dirname(CommonJS),import.meta.url(ESM)node:fs,node:http,node:path,node:crypto- Full server privileges—validate input, guard file paths, manage secrets via env vars
Shared
Modern ECMAScript features—const/let, arrow functions, classes, modules, promises, Map/Set—work in both when supported by the runtime version. Always check Node LTS release notes for feature support.
Important interview questions and answers
- Q: Can you use
documentin Node?
A: No—there is no DOM. Use templates on the server (EJS, React SSR) or return JSON for SPAs. - Q: Is
fetchavailable in Node?
A: Yes in modern Node (18+ globally)—earlier versions needednode-fetchorhttp. - Q: Why share JS on client and server?
A: One language for full-stack teams, shared validation schemas (e.g. Zod), and less context switching—trade-off is coupling if not modularized.
Self-check
- Name two globals available in Node but not in the browser.
- Why must secrets live on the server only?
Interview prep
- window vs global in Node?
Browser JS has
windowand DOM APIs; Node hasglobalThis,process, and built-in modules likefsandhttp—no document or localStorage.