
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Statement Terminators (Semicolons)
|
393
more readable. For example, the following is another legitimate way to rewrite the
earlier assignment expression, but it is obviously harder to read:
x =
10
+ 5
/ y;
Notice that the statement is terminated by the semicolon, not the line breaks. In
nearly all cases, line breaks are inconsequential and do not act as statement termina-
tors. Hence, we often use one or more line breaks (in concert with spaces or tabs) to
make complex statements easier to read:
myNestedArray = [[x, y, z],
[1, 2, 3],
["joshua davis", "yugo nakamura", "james patterson"]];
// Much nicer than:
myNestedArray = [[x, y, z], [1, 2, 3],["joshua davis","yugo nakamura",
"james patterson"]];
// And also nicer than:
myNestedArray = [[x, y, z],
[1, 2, 3],
["joshua davis","yugo nakamura","james patterson"]];
You don’t need to do anything special to break a statement onto more than one line.
Simply add a carriage return and keep typing. For good advice on making your code
more readable, see Code Complete, by Steve McConnell (Microsoft Press). However,
there are times when line breaks may be misinterpreted as statement terminators, as
we’ll see in the next section.
Note that whitespace within the quotes that delimit a string is relevant, whereas
whitespace outside the quotes is ignored. Compare ...