[英]Javascript - Global scope or local scope, not able to figure it out
I am not able to figure it out if d is a global variable or because of (,) it will have a local scope like abc? 我不能弄清楚d是全局变量还是因为(,)它具有像abc这样的局部作用域?
I think a , b and c have local scope and d is having a local scope. 我认为a,b和c具有局部范围,而d具有局部范围。
function something(param) {
var a, b, c= {
someNumber: 7,
someObject: {},
},
d= {}
}
d
是局部的,因为逗号将其保留在var
语句中。
You can theorize all you want, but nothing beats solving it walking : 您可以理论化所有您想要的东西,但是没有什么可以解决它的问题 :
function something(param) {
var a, b, c= {
someNumber: 7,
someObject: {},
},
d= {}
}
something()
console.log(d);
produces: 产生:
ReferenceError: d is not defined
ReferenceError:未定义d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.