CodeMIRAI
0 XP

Introduction to JavaScript

2 min read 3 runnable examples Quiz included

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

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:

LanguageJobExample
HTMLstructure and contenta heading, a button
CSSappearancethe button is blue and rounded
JavaScriptbehaviourclicking the button shows a message

Here is all three working together. Press Run, then click the button in the result.

HTML
<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

WhereExamples
Browsers Chrome · Firefox · Safari
Servers Node.js · Bun
Interfaces React · Vue · Angular
Desktop apps Electron, which VS Code is built with

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.

JavaScript
let year = 2026;
let launched = 1995;
console.log("JavaScript is", year - launched, "years old");
Finished this lesson?Mark it complete to earn +20 XP and move your progress on.