You are confusing two conventions for comparison with undefined:
x === undefined
and
typeof x === 'undefined'
Thee former used to be considered poor style because undefined
was simply a variable, which when used before initialization had the value undefined
, which could however be changed to anything, including null
or even 3
. With modern JS that's much less of a worry - undefined
is now non-writeable, meaning you only really need to worry about the value of undefined
inside of everyone's favorite JavaScript bugbear, with
blocks.
For backwards compatibility, sometimes typeof x === 'undefined'
is preferred, but in modern practice x === undefined
is fine. However, if you are comparing x
against both null
and undefined
, x != null
is IMO clearer and more concise, although some people do advocate never using ==
and !=
in JavaScript.