Javascript: The Definitive Guide

Previous Chapter 5 Next
 

5.13 The Empty Statement

One final legal statement in JavaScript is the empty statement. It looks like this:

;
Executing the empty statement obviously has no effect and performs no action. You might think that there would be little reason to ever use such a statement, but it turns out that the empty statement is occasionally useful when you want to create a loop that has an empty body. For example:

// initialize an array a
for(i=0; i < a.length; a[i++] = 0) ; 
To make your code clear, it can be useful to comment your empty statements as such:

for(i=0; i < a.length; a[i++] = 0) /* empty */ ; 


Previous Home Next
return Book Index Summary of JavaScript Statements