读书人

宣言变量时是否使用var的不同

发布时间: 2012-11-23 00:03:43 作者: rapoo

声明变量时是否使用var的不同

是否使用var声明变量,结果是不同的,使用var声明的变量是局部的,反之是全局的!

?

For example, when we use the keyword?var, the JavaScript will create a variable in the current (or local) scope of the code block you are adding the code to. If we skip the?var?keyword, the variable will still be created, but in the global scope of your program, which means it would be visible from anywhere in the (.js) file. Again, try to avoid using globals.

读书人网 >Web前端

热点推荐