该
typeof运营商将检查变量真的不确定。
if (typeof variable === 'undefined') { // variable is undefined}该
typeof运营商,不同于其他运营商,不会抛出 的ReferenceError 与未声明的变量使用时例外。
但是,请注意
typeof null将返回
"object"。我们必须小心避免将变量初始化为的错误
null。为了安全起见,我们可以改用以下方法:
if (typeof variable === 'undefined' || variable === null) { // variable is undefined or null}有关使用严格比较
===而不是简单相等的更多信息
==



