Because I'm used to C and Java, I've found Javascript's lack of block scope a little irksome. Sometimes I find myself wanting to declare and then immediately execute an inline function just to overcome this issue. For example:
...
if (x == 0) {
(function () {
var i;
for (i = 0; i < 10; i++) {
...
}
})();
}
...
Otherwise, I feel the need to declare all of the variables for a function at the top of the scope, in order to avoid forgetting about the lack of block scope. But having a huge var statement at the beginning of a function looks clumsy to me.
The way I've shown above feels wasteful, but I don't have any idea of what it costs to declare inline functions in the first place. Is doing it this way a bad idea? Is there a better way to solve my qualm with Javascript's scoping?