Home > Web Front-end > JS Tutorial > js变量作用域

js变量作用域

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 09:55:05
Original
1122 people have browsed it

当在函数内部定义变量时,一定要用var定义,否则该变量将是全局变量。

实例:

<code>function fn1{    
   b=2;
   alert(b);
}</code>
Copy after login

此时,如果页面执行了fn1函数,则b变量将成为全局变量。

 

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
Latest Issues
JavaScript 中的“变量”变量
From 1970-01-01 08:00:00
0
0
0
静态变量
From 1970-01-01 08:00:00
0
0
0
第一个javaScript变量
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template