Frontend Labs
⋯

2. Running JS: console, Node, and your first script

Three environments you'll write JS in, and what's different about each:

  • Browser console/DevTools: has window, document, and every Web API (fetch, localStorage, Web Workers) but no filesystem/require.
  • Node.js: has fs, process, require/CommonJS (or ESM with "type": "module"), but no window/document/DOM — it's a server-side runtime, not a browser.
  • <script> tag in an HTML file: same globals as the console, but runs in the page's actual execution context, wired to real DOM elements.
// hello.js — run with `node hello.js`
console.log("Hello from Node", process.version);

// index.html — open directly in a browser
// <script>
//   console.log("Hello from the browser", navigator.userAgent);
//   document.body.textContent = "Hello, DOM";
// </script>

"use strict" (automatic in ES modules and classes) turns silent mistakes into thrown errors: assigning to an undeclared variable, duplicate parameter names, and several others. There's no reason to write new non-strict code in 2026 — always target modules or explicit strict mode.

Generated from real-life-JS-guide.md · 8 Oct 2026 16:36