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.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn