Code is Made of Statements
JavaScript Statements
A JavaScript program is a list of instructions called statements. Learn how they're written, separated, and grouped.
What you'll learn
- Read a JavaScript program as a sequence of statements
- Use semicolons and whitespace correctly
- Group statements into a code block with `{ }`
A JavaScript program is a list of statements — instructions the browser runs one after another.
let x = 5;
let y = 10;
console.log(x + y); Each line above is one statement. They run from top to bottom, in
order: declare x, declare y, then log their sum.
Semicolons
Statements end with a semicolon ;. JavaScript can insert most missing
semicolons for you (this is called automatic semicolon insertion),
but a few cases trip up the inserter — so writing them yourself
avoids surprises.
let name = "Ada"; let age = 36; console.log(name, age); You can put multiple statements on one line if you separate them with semicolons — but readability suffers. Use one statement per line.
Whitespace
JavaScript ignores extra spaces and line breaks inside a statement. You can format your code however you like.
let total = 5
+ 10
+ 15;
console.log(total); Use whitespace and line breaks to make your code easier to read. There are no points for compact code.
Code Blocks
A group of statements wrapped in { } is called a block. Blocks
are used everywhere — inside if, for, function, class, and so
on — to say “these statements belong together”.
{
let message = "inside a block";
console.log(message);
}
console.log("outside the block"); Blocks also create scope — variables declared inside a block don’t leak out. We’ll come back to scope when we talk about variables.
Keywords
Some words have special meaning in JavaScript — like let, const,
if, else, for, function, return, class. These are called
keywords, and you can’t use them as names for your variables.
We’ll meet most of these one by one over the next lessons.
Up Next
You’ve seen statements. Now let’s look at the grammar inside them — values, operators, and identifiers.
JavaScript Syntax →