JavaScript Tutorial/Language Basics/Semicolon

Материал из Web эксперт
Перейти к: навигация, поиск

End-of-line semicolons are optional.

JavaScript allows the developer to decide whether or not to end a line with a semicolon.

If the semicolon is not provided, JavaScript considers the end of the line as the end of the statement.

var test1 = "red"
var test2 = "blue";

The Semicolon

JavaScript executes your code accordingly even if you forget a semicolon at the end of the line.

You must use a semicolon to separate the two pieces of code when putting two independent pieces of code on one line.

// Declare 2 numeric variables on the same line
var varA = 5; var varB = 0.06;