Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The for class of statements should have the following form:
for (initialization; condition; update) {
statements
}
for (variable in object) {
statements
}
Variables should not be declared in the initialization section of
a for statement.
// Good
var i,
len;
for (i=0, len=10; i < len; i++) {
// code
}
// Bad: Variables declared during initialization
for (var i=0, len=10; i < len; i++) {
// code
}
// Bad: Variables declared during initialization
for (var prop in object) {
// code
}
When using a for-in statement,
double-check if you need to use hasOwnProperty() to filter out object
members.