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

来源:互联网 发布:java ftp上传文件 0kb 编辑:程序博客网 时间:2024/05/24 07:37

是否使用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.