Home > Web Front-end > JS Tutorial > body text

js变量作用域

WBOY
Release: 2016-06-01 09:55:05
Original
1069 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!