Variable scope problem in Js :
1. No block-level scope. Variable scopes in Js are not bounded by {}, unlike C/C++/Java.
like:
The code copy is as follows:
if(true){
var name = "qqyumidi";
}
alert(name); // Result: qqyumidi
Js will add variables defined in if to the current execution environment, especially when using for loops, you need to pay attention to differences from other languages.
The code copy is as follows:
for(var i=0; i<10; i++){
;
}
alert(i); // Result: 10
This is just a personal understanding. If there are any mistakes, please tell me.