Which is not correct in normal Javascript and i can't imagine this is desired behaviour. The variable index should not be in the scope of test2(). This caused for some real strange behaviour in my code, because i'm using a variable with the same name. Besides the issue of the variable being accessible, it's apparently by reference... if you set this variable to a new value you mess up the iteration of your loop in test1(). It took me quite some time to figure out what is causing this weird behaviour...

I understand your point, but i didn't expected such elementary behaviour to differ from Javascript. But thank you for pointing out the local keyword. That indeed solves my problem. As Javascript developer this is kind of mind f*ckery to my mind