I have something similar to the following code in Javascript:
func1() {
for(i = 2; i < 5; i ++) {
console.log(i);
func2(i);
}
}
func2(x) {
for(i = 100; i < 200; i ++) {
do something
}
}
Apparently the output for my this program is one single line with a 2, although it worked if I change the index name for one of the for loop from i to ii for example.
Is it an expected behavior in javascript that the i in the for loop in func1 actually changes to 100 after calling func2 the first time?
If this is true is there any way to get around this issue without naming each index differently? This is extremely annoying when there are a lot of function calls nested.
ideclared? what is its scope?iis global (and the same variable for both functions) in this code