Why is the final output is 3? But not in 2 "
CodePudding user response:
Arr [0] the function of the array is read at the end of the cycle of the output value, IYour loop condition is the I & lt; 3, only does not meet the conditions of circulation will end, that is when I equals 3 cycle will end, then read the output value of the I, of course, is 3
CodePudding user response:
CodePudding user response:
1. Because you are using var variables defined for loop again is a global equivalent you defined in the global variable I2. When you call arr [0] () function of the function will output I, but the for loop is executed at this time, I will also become a 3
3. Understanding you can take a look at scope chain related knowledge
4. If you want to 0 the simplest method is to change the var to let statement