Home > Web Front-end > JS Tutorial > A brief discussion on Javascript variable scope issues_javascript skills

A brief discussion on Javascript variable scope issues_javascript skills

WBOY
Release: 2016-05-16 16:26:17
Original
1121 people have browsed it

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:

Copy code The code is as follows:

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.

Copy code The code is as follows:
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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template