What is the difference between Node.js and browser-side JavaScript?
Both run JavaScript on the V8 engine, but they operate in completely different environments with different APIs and purposes.
1. Environment
Browser — runs in a sandboxed browser tab, for client-side UI.
Node.js — runs on the server or local machine, for backend and system-level tasks.
2. Global object
Browser —
window(anddocument,navigator).Node.js —
global(andprocess,Buffer).
3. APIs available
Browser — DOM,
fetch,localStorage,alert, Web APIs.Node.js —
fs,http,crypto,os,child_process,stream— no DOM.
4. Module system
Browser — ES Modules (
import/export) natively.Node.js — supports both CommonJS (
require) and ES Modules.
5. Security model
Browser — sandboxed, restricted (same-origin policy, no file system access).
Node.js — full access to the OS, filesystem, and network.
Structure your answer around three axes: available APIs (DOM vs file system), security model (sandboxed vs full system access), and module systems. This shows a systematic understanding.