JavaScript is the language that makes a web page respond to the person using it, and since 2009 it runs on servers too.
Complete lesson & earn 250 PX
EXERCISE
1Every web page is built from three languages that each own a different job, and JavaScript is the one that makes things happen.
EXERCISE
2For its first fourteen years JavaScript could only run inside a web page, and then Node.js took the engine out and put it on the server.
EXERCISE
3The language was built in ten days in 1995, renamed for marketing reasons, and spent a decade being dismissed. That history explains a lot of what you will meet later.
A web page is built from three separate languages, and each one is responsible for exactly one thing. HTML says what is on the page and what it means: this is a heading, this is a paragraph, this is a button. CSS says how it looks: the colours, the spacing, the fonts. JavaScript says what happens: what changes when the button is clicked, what loads when you scroll, what appears when a form is filled in wrongly.
The division is strict and worth taking seriously, because it is the reason three separate languages exist rather than one. Each can be changed without touching the others.
HTML puts a button and a line of text on the page:
<button id="lamp">Turn on the light</button>
<p id="status">The room is dark.</p>
That is the whole page. It has structure and meaning, and a browser can display it right now.
CSS decides what it looks like, and changes nothing about what it is:
#lamp {
background: #6d28d9;
color: white;
padding: 10px 18px;
}
The button is now purple with white text and some breathing room. It is still a button, still says the same words, and still does nothing when clicked.
JavaScript is the only one of the three that can change the page after it has loaded:
const status = document.getElementById("status");
status.textContent = "The room is bright.";
Two lines. The first finds the paragraph by its id. The second replaces its text. HTML could not do that, because HTML describes the page as it starts. CSS could not do it either, because CSS describes appearance, not content.
That is the real dividing line. HTML and CSS describe a page. JavaScript changes it while someone is using it. A page with no is not broken, it is a document you read rather than an application you use. Almost everything you find interesting on the web is the third language doing its job: a search box that suggests as you type, a total that updates the instant you change a quantity, a form that tells you the password is too short before you submit it.
A browser runs JavaScript using a component called an engine. Chrome's engine is named V8, and its only job is to take JavaScript text and execute it.
In 2009 someone had a simple idea with very large consequences: the engine does not actually need the browser. Take V8 out, wrap it in code that can read files from a disk and listen on a network port, and you have a way to run JavaScript anywhere. That wrapper is Node.js, and it is why JavaScript is no longer a language for web pages.
The language itself is identical in both places:
const price = 20;
const quantity = 3;
const total = price * quantity;
console.log(total);
That runs the same way in a browser tab and on a server, because none of it depends on where it is. Variables, arithmetic, and printing a value are the language.
What differs is what the surroundings provide:
document.title = "My shop";
That only works in a browser. document is the page, and a server has no page.
const fs = require("fs");
That only works in Node. require reaches for files on a disk, and a browser tab has no disk to reach into.
Neither of those is JavaScript. They are things the environment hands to JavaScript, and the distinction matters because it explains a whole category of confusing error. When code works in one place and fails in the other with a message like document is not defined, nothing is wrong with the language or with your code. You asked for something the surroundings do not have.
Why this changed how software gets built: before 2009, a web application usually needed two languages, one for the page and a different one for the . After , one language could do both, and then rather more than both. Build tools, command-line utilities and desktop applications are all written in JavaScript now. VS Code, Slack and Discord are each a browser engine with JavaScript inside it.
Pro Tip: When something works in one environment and not the other, suspect the surroundings before the language.
const, functions, arrays and objects behave identically everywhere.documentandwindoware the browser's;requireandprocessare Node's. The error message usually names the missing thing directly.
JavaScript was created in 1995 by one person, Brendan Eich, at a company called Netscape. He was given ten days to design and build it. Not ten days to plan it, ten days to have something that worked in a browser.
That deadline explains a great deal about the language, and it is worth knowing early. Some of the odd corners you will meet later are not there because they were good ideas. They are there because there was no time to reconsider them, and once millions of pages depended on them they could never be removed without breaking the web.
The name is the first thing that confuses people, and it is worth settling now. It was called Mocha while it was being built, then LiveScript when it shipped, then renamed JavaScript a few months later. The rename was a marketing decision. Java was the popular language of 1995, and Netscape had a partnership with the company that made it.
JavaScript and Java are unrelated languages. They share four letters and nothing else. Confusing them is like confusing a car with a carpet.
Here is roughly everything it could do at the start:
alert("Hello!");
That was the scope of it: pop up a small message, check that a form field was not empty, swap an image when the mouse moved over it. Nobody expected it to last, and for about a decade it was widely regarded as a toy.
Four things changed that.
1995 created at Netscape in ten days
1997 standardised, which is why versions are called ES5, ES6 and so on
2008 Google's V8 engine made it genuinely fast
2009 Node.js took it out of the browser and onto servers
2015 ES6, a large modernisation: let, const, arrow functions, classes
The 1997 standard mattered because browsers had started inventing their own incompatible versions, and code that worked in one simply failed in another. Agreeing on one definition is what made it possible to write JavaScript once.
The 2008 speed work mattered because it moved the language from "fine for small effects" to "fast enough to build an entire application in". Gmail and Google Maps were early proof that a web page could feel like a real program.
Today JavaScript is the most widely used programming language in the world, and it is the only one that runs natively in every browser on every device. You are also learning it at a good moment. The version taught in this course is the modern one, cleaned up in 2015 and improved steadily since.
console.log("Hello!");
That line does today what alert did in 1995, and it is the one you will actually use. If you find an older tutorial that looks quite different from this course, its age is usually the reason.
HTML is the content, CSS is the look, JavaScript is the behaviour. Node.js took the same language out of the browser and onto servers, so one language now covers both sides of an app.