Chapter I · The Language
What is JavaScript?
JavaScript is the language that makes web pages do things — respond to clicks, update themselves, talk to servers — without asking the page to reload.
01 What is JavaScript?
JavaScript is a programming language — a precise, written way of telling a computer what to do. It was built for the web, and every modern browser understands it natively, which means it runs the moment a page loads, with no separate installation.
Two other languages usually sit alongside it: HTML describes the structure of a page, and CSS describes its appearance. JavaScript adds behavior — the part that reacts, calculates, and changes things over time.
It has also grown well beyond the browser. The same language now runs on servers, in command-line tools, and inside mobile apps, using engines that execute JavaScript outside of a web page entirely.
Why does this matter? Before JavaScript existed, web pages were static documents — you could read them, but the page itself couldn't respond to anything you did. JavaScript was created in 1995 (by Brendan Eich, in about ten days, for Netscape Navigator) specifically to close that gap. Every interactive thing you take for granted on the modern web — a form that validates itself as you type, a map you can drag, a feed that loads more posts without reloading the page — exists because JavaScript can run after the page has loaded, in direct response to what the user does.
02 Simple Example
Here is a small piece of JavaScript reacting to a moment in time — the click of a button.
const button = document.querySelector("button");
button.addEventListener("click", () => {
console.log("The button was clicked.");
});
Nothing happens until the click occurs. JavaScript is comfortable waiting for the world to do something — that reactive quality is central to how it works, and it's a theme this book returns to often.
03 How It Works
When a browser loads a page, it hands any JavaScript to a JavaScript engine built into the browser. The engine reads the code, converts it into a form the machine can run, and executes it — line by line, top to bottom, unless it's told to wait or repeat.
The engine is the bridge between the code you write and what the page actually does.
04 Step-by-Step
The browser downloads the HTML page.
It finds a <script> tag or linked .js file and hands the code to the JavaScript engine.
The engine parses the code, checking that it's written correctly.
The engine executes the code from top to bottom.
Any part of the code that listens for events — clicks, typing, timers — stays ready to run later, in response to those events.
05 Mental Model
"JavaScript is the stage crew of a web page — invisible until something needs to move."
HTML builds the set, CSS lights and dresses it, and JavaScript is the crew making things move on cue: opening a menu, validating a form, refreshing a feed.
06 Common Mistakes
Confusing JavaScript with Java. Beyond a shared marketing-era name, the two languages have nothing in common — different creators, different syntax, different type systems, and different runtimes. Saying "I know Java" tells an interviewer nothing about your JavaScript skills, and vice versa.
Thinking JavaScript only runs in browsers. Many beginners are surprised the first time they see JavaScript power a backend API, a build tool, or a mobile app. The language itself doesn't know or care what environment it's running in — that's determined entirely by which engine and which host APIs (browser DOM vs. Node.js file system, for example) are available.
07 Interview Questions
Q: Is JavaScript the same as Java?
No — they share a name for marketing reasons from 1995, but they're unrelated languages with different syntax, type systems, and runtimes.
Q: Where does JavaScript run besides the browser?
On servers (Node.js, Deno, Bun), in CLI tools, and inside mobile/desktop apps via embedded engines — the language itself is host-independent.
Key Takeaway
JavaScript is a language built to add behavior to web pages — and it now runs almost anywhere, not only in browsers. Everything else in this book builds outward from that one idea.