使用var关键字定义变量是一个好习惯

来源:互联网 发布:直通车优化助手 编辑:程序博客网 时间:2024/05/14 13:58

You can declare a variable in two ways:

  • With the keyword var. For example, var x = 42. This syntax can be used to declare bothlocal and global variables.
  • By simply assigning it a value. For example, x = 42. This always declares aglobal variable and generates a strict JavaScript warning. You shouldn't use this variant.
其实我觉得应该加强语法规则,要么用var关键字要么用global关键字,这样就不会出岔子了。
原创粉丝点击