JavaScript: The Definitive Guide

Previous Chapter 2
Lexical Structure
Next
 

2.3 Optional Semicolons

Simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. This serves to separate them from the following statement. In JavaScript, however, you are allowed to omit this semicolon if your statements are each placed on a separate line. For example, the following code could be written without semicolons:

a = 3;
b = 4;

But when formatted as follows, the semicolons are required:

a = 3; b = 4;

Omitting semicolons is not a good programming practice; you should get in the habit of using them.


Previous Home Next
Whitespace and Line Breaks Book Index Comments

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
Hosted by uCoz