Loading lessons...
JavaScript Statements
JavaScript Statements
A program is a list of statements that the computer executes in order.
What is a statement?
A statement is one instruction. It can do things like declare a variable, make a decision, or call a function:
let message = "Hello"; // statement 1
document.write(message); // statement 2
Statement keywords
Common JavaScript statement keywords:
let,var,constdeclare variables.if,else,switchmake decisions.for,while,docreate loops.functionandreturndefine and return from functions.breakandcontinuecontrol loops.try,catch,throwhandle errors.
Statement blocks
Statements can be grouped in blocks with curly braces { and }:
if (age > 18) {
console.log("Adult");
}
Execution order
JavaScript runs statements top to bottom, one at a time. This is called sequential execution.
The semicolon rule
Each statement usually ends with a semicolon. The semicolon tells JavaScript where one statement ends and the next begins.
TL;DR
- A statement is one instruction.
- Keywords like if, for, and function start statements.
- Blocks group statements with curly braces.
- Statements run top to bottom.
- End statements with semicolons.