Statements
Statements are list of programming instructions used to control specific actions in JavaScript. JavaScript statements are made of:
- Values
- Operators
- Expressions
- Keywords
- Comments
Semicolon
Semicolon indicates the end of a statement. If semicolon is not inserted, the next line could be taken as an extension of the first.
var x = 1;
var y = 2 + x;
var z = 3 + y;
console.log(x, y, z);
// expected output: 1 3 6
When semicolon is not used, the interpreter will take next line as a continuation for the current line.
Note
We can group multiple statements together in one line by separating them by a semicolon. Even though JavaScript ignores multiple spacing, it is standard practice to use a semicolon at the end of a statement.