在JavaScript中,为什么第二行返回undefined
而不是错误?
var apple = 'apple';
apple.colour; //undefined
计算为出现在.
or[]
运算符左侧的原始值的表达式将自动“包装”在适当类型(字符串,数字,布尔值)的对象中。
因此
"hello".length
被评估为
new String("hello").length
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句