Learning JavaScript from scratch in 2026: a practical guide
JavaScript is the language of the web: it runs in every browser with nothing to install, and it is the only way to make a page interactive. Learning it opens the door to websites, apps and — with Node.js — the backend too.
This guide starts from zero. Every example runs right here: hit "Try it" and watch the result.
Your first message
console.log("Hello, world!");console.log prints a value. It is the tool you will use most to understand what your code does.
Variables
let name = "Luke";
const age = 30;
console.log(name);
console.log(age + 1);let creates a variable you can change, const one that stays fixed. Use const when a value must not change: it makes code safer.
Decisions: if / else
let hour = 20;
if (hour < 12) {
console.log("Good morning");
} else if (hour < 18) {
console.log("Good afternoon");
} else {
console.log("Good evening");
}Conditions go in round brackets, the block in curly braces. Change hour and re-run.
Repetition: the for loop
for (let i = 1; i <= 5; i++) {
console.log("Line number " + i);
}i++ increases i by one each round. We join text and number with +.
Functions
function greet(name) {
return "Hi, " + name + "!";
}
console.log(greet("Sara"));
console.log(greet("Mark"));A function is a reusable block: write it once, call it as many times as you like. It is the building block of every serious program.
Lists (arrays)
let groceries = ["bread", "milk", "coffee"];
for (let item of groceries) {
console.log("To buy: " + item);
}
console.log("Total items: " + groceries.length);An array holds several ordered values; .length tells you how many.
Where to go from here
The JavaScript path starts exactly here and goes up to objects, the DOM, async and modern functions, always with browser-runnable exercises. The first chapters are free; in the playground you can try JavaScript freely.