JavaScript Statements
A statement is one instruction that tells the browser to do something. A JavaScript program is a list of statements.
One statement
This program holds one statement. The statement prints one line to the console.
console.log("One instruction");Statements in order
These statements run from top to bottom. The console shows the lines in that same order.
console.log("First");
console.log("Second");
console.log("Third");Two on one line
A semicolon lets two statements share one line. One statement per line stays easier to read.
console.log("Left"); console.log("Right");Example
console.log("Program start");
console.log("Step one done");
console.log("Step two done");
console.log("Program end");Key points
- Each statement tells the browser to do one thing.
- Statements run in order, from the top of the script to the bottom.
- A semicolon ends a statement.
- One statement per line is the common habit.
- Code block: a group of statements inside curly braces
In this example, the program holds four statements. The first statement prints the start line. The next two statements print the step lines in order. The last statement prints the end line.
Try it Yourself
Edit the code, then press Run.
Runs in your browser โ the preview under the editor is the real result. Nothing is sent to a server. The code runner panel (right) does the same with more room.
Exercise
What does a semicolon do in JavaScript?