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".
For local variables (which you know are declared somewhere), no such error would occur, hence the identity check.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…