If I run the code below it acts as expected. (Expected being that both normal code languages AND JavaScript have "local scope" in functions) Thus the variable is not changed by the sub function.
testFunc(0);
var bFunc = function(){
for(H=1; H<5;H++){}
alert("bFunc H:"+H);
};
var testFunc = function(H){
alert("CallId 1, H: " + H);
bFunc();
alert("CallId 2, H: " + H);
};
When running the code below it fails with the variable being modified inside the sub function:
forFunc();
var cFunc = function(){
for(zzz = 0; zzz < 30; zzz++)
{}
}
var forFunc = function(){
for(zzz = 0; zzz < 5; zzz++){
alert("zzz:"+zzz);
cFunc();
}
alert("Scope leak if not 5:"+zzz);
}