5.2 Compound and Empty Statements
x = Math.PI;
cx = Math.cos(x);
console.log("cos(π) = " + cx);
// Initialize an array a for(i = 0; i < a.length; a[i++] = 0) ;
Note that the accidental inclusion of a semicolon after the right parenthesis of a for loop, while loop, or if statement can cause frustrating bugs that are difficult to detect. For example, the following code probably does not do what the author intended:
if ((a == 0) || (b == 0)); // Oops! This line does nothing...
o = null; // and this line is always executed.
When you intentionally use the empty statement, it is a good idea to comment your code in a way that makes it clear that you are doing it on purpose. For example:欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/27631.html