What Is JavaScript? The Programming Language of the Web
JavaScript is the programming language that makes web pages interactive. Learn how it works alongside HTML and CSS, and why it runs nearly everywhere.
JavaScript is the programming language that makes web pages interactive. While HTML gives a page its structure and CSS gives it its visual style, JavaScript is what lets things happen — buttons respond to clicks, forms validate input, content updates without a full page reload. Today it runs in every major browser and, via runtimes like Node.js and Bun, on servers too.
The three layers of the web
Every modern web page is built from three technologies working together:
- HTML defines the content and structure — headings, paragraphs, images, links.
- CSS controls the presentation — colors, fonts, layout, spacing.
- JavaScript adds behavior — anything that changes or responds over time.
HTML and CSS are declarative: you describe what you want and the browser renders it. JavaScript is a full programming language with variables, functions, loops, and logic. It sits in <script> tags inside an HTML file, or more commonly in separate .js files that the page loads.
How JavaScript works in the browser
When a browser loads a page, it parses the HTML and builds the DOM (Document Object Model) — a live tree of all the elements on the page. JavaScript can read and modify that tree at any time. Want to hide an element? Change some text? Add a new list item? That’s all DOM manipulation.
JavaScript is also event-driven. You attach listeners to events — a click, a keypress, a network response — and your code runs when that event fires. This is the pattern behind virtually every interactive UI on the web.
// Change the heading text when a button is clicked
const button = document.querySelector('#greet-btn');
const heading = document.querySelector('h1');
button.addEventListener('click', () => {
heading.textContent = 'Hello, world!';
});
Learn more about how the DOM works in our DOM explainer and how events are queued and dispatched in JavaScript Event Loop Explained.
Fetching data and talking to APIs
One of JavaScript’s most important jobs is communicating with servers without reloading the page. The fetch API lets you make HTTP requests and handle the response in your code:
async function getUser(id) {
const response = await fetch(`/api/users/${id}`);
const user = await response.json();
console.log(user.name);
}
The async/await syntax, introduced in ES2017, makes asynchronous code much easier to read and write than the older callback or Promise-chaining styles.
Where JavaScript runs today
JavaScript began as a browser-only language. That changed with Node.js, which brought JavaScript to the server using the same V8 engine that powers Chrome. You can write a web API, a CLI tool, or a build script in JavaScript and run it on any machine without a browser. Bun is a newer, faster runtime with the same idea.
JavaScript is also the foundation for most front-end frameworks — React, Vue, Svelte, and others — which add component-based architectures on top of the core language.
JavaScript and TypeScript
TypeScript is a superset of JavaScript that adds static type annotations. You write TypeScript, run a compiler, and get plain JavaScript out. The types vanish at runtime, but they catch entire classes of bugs before your code ships. If you work on a large codebase or a team, TypeScript is worth learning once you’re comfortable with JavaScript basics. See our guide on Getting Started with TypeScript.
Takeaway
JavaScript is the one language you cannot avoid if you build for the web. It powers the interactivity on every page you visit, runs on servers through Node.js and Bun, and underpins the entire ecosystem of modern front-end frameworks. Its quirks are real, but so is its reach — mastering JavaScript opens more doors than almost any other language in software development.
Keep reading
Takina · · 4 min read TypeScript Abstract Classes, Explained
Abstract classes in TypeScript define shared implementation plus methods subclasses must fill in. How they differ from interfaces and when to reach for them.
Takina · · 4 min read What Is a Lockfile? Reproducible Dependency Installs
A lockfile records the exact dependency versions your package manager resolved, so every install — from your laptop to CI — reproduces the same tree.
Takina · · 3 min read TypeScript's never Type, Explained
never represents values that can't exist — it marks unreachable code, exhaustive switches, and functions that always throw or loop forever.