The language is the same everywhere. What changes is what the runtime gives you around it.
The browser
In a browser, JavaScript gets the page and everything around it: document, window, events, fetch, localStorage, the screen, the URL. There is no file system and no access to the operating system.
Node.js
Node.js is a runtime that lets you run JavaScript outside a browser, on your computer or a server. It uses the same V8 engine as Chrome, but instead of the page it gives you tools such as reading files, running a web server and talking to databases.
node hello.js
console.log("Hello from Node.js");
There is no document in Node.js, because there is no page. And fs (file system) does not exist in the browser. The language works the same; the extra tools are different.
| Browser | Node.js | |
|---|---|---|
| Page and DOM | Yes | No |
fetch | Yes | Yes (modern versions) |
| Read files on disk | No | Yes |
| Typical use | Interfaces on web pages | Servers, command-line tools, build tools |
npm and packages
Node.js comes with npm (Node Package Manager), a tool and online registry of reusable code called packages. Front-end projects use it too: tools that bundle and build your JavaScript for the browser are installed with npm. You do not need it to start learning.
Other places JavaScript runs
Other runtimes exist, such as Deno and Bun, and JavaScript also runs inside apps, desktop programs and some devices. The idea is always the same: an engine plus tools around it.