Every time anyone mentions testing against undefined
, it\'s pointed out that undefined
is not a keyword so it could be set to \"hello\", so you sho
You can use undefined
in your code when coding for browsers supporting ECMAScript 5.1 as it is immutable according to the language specification.
Also see this compatibility table or this caniuse ECMAScript 5 to see that all modern browsers (IE 9+) have implemented immutable undefined
.
There's a simple solution to that: compare against void 0
which is always undefined.
Note that you should avoid ==
as it may coerce the values. Use ===
(and !==
) instead.
That said, the undefined variable may be set by error if someone writes =
instead of ==
when comparing something against undefined
.