Variable scope problem in Js:
1. There is no block-level scope. The variable scope in JS is not bounded by {}, unlike C/C/Java.
For example:
if(true){
var name = "qqyumidi";
}
alert(name); // Result: qqyumidi
JS will add the variables defined in if to the current execution environment. Especially when using for loops, you need to pay attention to the differences with other languages.
for(var i=0; i<10; i ){
;
}
alert(i); // Result: 10
This is just my personal understanding. If there are any mistakes, please let me know.