I think this is actually a problem with JSLint. It produces the following error:
Unexpected 'typeof'. Compare directly to 'undefined'.
I think this is bad advice. In JavaScript, undefined is a global variable that is usually undefined. But some browsers allow scripts to modify it, for example: window.undefined = 'defined' . If so, comparing directly with undefined may lead to unexpected results. Fortunately, current ECMA 5 compatible browsers do not allow undefined (and throw an exception in strict mode).
I prefer typeof someVar === "undefined" as you wrote, or someVar in window , as Sussey suggested.
bfavaretto Jul 21 '12 at 22:37 2012-07-21 22:37
source share