For undeclared variables, typeof foo
will return the string literal "undefined"
, whereas the identity check foo === undefined
would trigger the error "foo is not defined" .
(对于未声明的变量, typeof foo
将返回字符串文字"undefined"
,而身份检查foo === undefined
将触发错误“ foo not defined” 。)
For local variables (which you know are declared somewhere), no such error would occur, hence the identity check.
(对于局部变量(您知道已在某处声明),不会发生此类错误,因此进行身份检查。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…