function test()
{
i = 10;
for (var i = 0; i < 1; i++);
alert(i);
}
I've tested this in Firefox. Does it give the same result in all browsers? Is the i in the for statement header local to the for statement or to the function?
function test()
{
i = 10;
for (var i = 0; i < 1; i++);
alert(i);
}
I've tested this in Firefox. Does it give the same result in all browsers? Is the i in the for statement header local to the for statement or to the function?
var
is function
scoped, therefore your function
function test()
{
i = 10;
for (var i = 0; i < 1; i++);
alert(i);
}
will declare an i
variable, override it with another one with similar name in a for
, resulting in 1 and this value will be alerted.