Blocks in JavaScript do not create scopes. This is different from many other languages (like Java or C).
In fact, Crockford has mentioned this as well: http://javascript.crockford.com/code.html
"JavaScript does not have block scope, so defining variables in blocks can confuse programmers who are experienced with other C family languages."
Which is why this code works:
(function() {
for (var i=0; i<100; i++);
alert(i);
})();Notice the variable `i` is accessible from outside the for-loop.