Introduction to JavaScript
JavaScript is the programming language of the web. Every modern browser runs it, which is why almost every interactive website you use (menus, forms, maps, chat) is powered by JavaScript. It also runs on servers with Node.js, in mobile apps, and in desktop apps like VS Code.
Your first JavaScript
console.log("Hello, world!");
console.log("2 + 2 is", 2 + 2);console.log() prints a value to the console. It is the first tool every JavaScript developer reaches for, because it shows you exactly what your code is doing.
HTML, CSS and JavaScript
A web page is built from three languages, each with a job:
| Language | Job | Example |
|---|---|---|
| structure and content | a heading, a button | |
| appearance | the button is blue and rounded | |
| behaviour | clicking the button shows a message |
Here is all three working together. Press Run, then click the button in the result.
<button id="hi">Say hello</button>
<p id="out"></p>
<script>
document.getElementById("hi").addEventListener("click", () => {
document.getElementById("out").textContent = "Hello from JavaScript!";
});
</script>Where you'll find JavaScript
| Where | Examples |
|---|---|
| Browsers | |
| Servers | |
| Interfaces | |
| Desktop apps |
Statements and semicolons
A JavaScript program is a list of statements, usually one per line, ending with a semicolon. JavaScript can often guess where a semicolon belongs, but writing them yourself avoids surprises.
let year = 2026;
let launched = 1995;
console.log("JavaScript is", year - launched, "years old");