JavaScript Tutorial/Language Basics/Semicolon
Версия от 18:52, 25 мая 2010; (обсуждение)
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.
<html>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Declare 2 numeric variables on the same line
var varA = 5; var varB = 0.06;
;
document.write(varA*varB);
-->
</SCRIPT>
</body>
</html>