JavaScript is the language that runs in every browser and on most servers. It is the only programming language built into web browsers, which means any interactive feature you see on a website almost certainly uses JavaScript.
What JavaScript does
JavaScript controls behavior on the web. That covers a wide range:
- responding when a user clicks a button or submits a form
- validating input before it is sent to a server
- updating page content without reloading
- animating transitions and visual effects
- handling real-time communication like chat or live updates
- running server-side code with Node.js, Bun, or Deno
The same language powers all of these. The environment changes, but the core language does not.
JavaScript in the browser
In the browser, JavaScript has access to the DOM (Document Object Model) — a programmatic representation of the page. Through the DOM, JavaScript can:
- read and change text, styles, and attributes
- add or remove elements
- listen for user events like clicks, key presses, and scrolls
- make network requests to fetch or send data
The browser also provides APIs for storage, geolocation, canvas rendering, and more. JavaScript is the interface to all of them.
JavaScript on the server
Outside the browser, JavaScript runs on servers through runtimes like Node.js. A runtime provides the JavaScript engine plus system-level APIs — reading files, starting network servers, accessing environment variables — that browsers do not expose.
Server-side JavaScript uses the same syntax and core features as browser JavaScript. The difference is what is available: instead of the DOM, you get file system access, HTTP servers, and database drivers.
Interpreted vs compiled, briefly
Languages are often described as either “interpreted” or “compiled.” JavaScript is generally called interpreted, but the distinction is blurrier than it sounds.
Modern JavaScript engines like V8 (Chrome, Node.js) compile code just before it runs — a technique called just-in-time (JIT) compilation. It is not pre-compiled into a binary, but it is not read line by line either.
For everyday purposes, the practical takeaway is:
- you write JavaScript and run it directly
- there is no separate compilation step you need to perform
- the engine handles optimization automatically
This is different from TypeScript, which requires an explicit compile step before running in a browser.
Dynamic typing
JavaScript is dynamically typed. Variable types are determined at runtime, not before the code runs.
let value = 42;
value = "hello";
value = true;
Each reassignment is valid. The type follows the value, not the variable. This flexibility makes JavaScript easy to start with, but it also means type errors only appear when the code actually runs — not before.
Dynamic typing is why practices like writing tests, being careful with data shapes, and checking assumptions matter in JavaScript. The language will not catch type mistakes ahead of time.
Where JavaScript is heading
JavaScript evolves through a standards process called ECMAScript. Each year, a new edition of the specification adds features that engines implement. Recent additions include:
- optional chaining (
?.) and nullish coalescing (??) - top-level
awaitin modules Array.prototype.at()for negative indexingObject.hasOwn()as a safer replacement forhasOwnProperty- non-mutating array methods:
toSorted(),toReversed(),toSpliced(),with() Array.fromAsync()for creating arrays from async iterables (ES2025)Promise.withResolvers()for creating promises with externally accessible resolve/reject functions- pattern matching and pipeline operator proposals (future)
Features are added gradually and conservatively. Code written to current standards runs in modern environments without change.
What to carry forward
- JavaScript runs in browsers and on servers
- it is the only language built into web browsers
- engines parse, compile, and execute code automatically
- dynamic typing means types are checked at runtime, not before
- the language evolves through the ECMAScript specification
The next lesson looks at how values and types actually work in JavaScript.