Thursday, July 19, 2007

Javascript "Empty Statement"

Spot anything wrong in the Javascript below?
var a=[];
//initialize array
for(int i = 0; i < 10; i++);
{
a[i] = 100;
}

Values in array a will be:
[undefined, undefined, 100]

The semicolon at the end of the for loop forms an "Empty Statement". So a[i]=100; is actually outside of the for loop!

No comments: