JavaScripts typeof
表达式检查null吗?JavaScript的typeof函数检查为null
var test = {};
console.log(typeof test['test']);//"undefined"
var test = null;
console.log(typeof test['test']);//TypeError: test is null
显然,但为什么错误,如果typeof null
是一个对象?
编辑:
我知道如何避免错误的类型,以及null
没有属性,但我不知道是那里的typeof
的行为作出解释。
,因为第一个测试是空 – karaxuna
'null'已经没有“测试”成员,试图访问它是非法的 –
的问题是你正在尝试读取'null ['test']的值' – goat