For example, is the program
var foo = 1; print(foo);
equivalent to
{ var foo = 1; print(foo); }
?
It is hard to decipher the ECMAScript spec to guarantee that it is so (which I think it is). Anyone have an opinion?
I think that ECMAScript has only one scope per function, and so your transfomation is valid, however, you'll have to test this.
It may be different because the foo variable was previously a global in the scope external to the block, while now it will be a local of the function, and undefined until the initialization is reached.
- Maxime