[英]Is there any difference/advantage of using var before a variable name in javascript?
I am learning javascript . 我正在学习javascript。 And I noted that the instructor was making variables in two ways .
而且我注意到讲师正在用两种方式进行变数。 first was (for example):
首先是(例如):
var name ="Any string here";
and second method was simply writing the variable name without writing var first : 第二种方法是简单地写变量名,而无需先写var:
name="Any string here";
And the result was same . 结果是一样的。 So , is there any difference between these two ?.
那么,这两者之间有什么区别吗? Which one is better to use ?
哪个更好用?
离开了var
使其成为一个全局变量,所以如果你有name
多个地方的代码,他们会互相覆盖。
var
before variable declaration. var
是一个不好的习惯。 var
. var
的变量的全局声明。 strict mode
using variable without declaration will cause Exception strict mode
使用不带声明的变量将导致异常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.