A common pattern is to make sure that undefined
is actually what it says it is, using some kind of wrapper function:
(function(undefined) {
// undefined will be undefined now, even if some idiot overwrote it.
})();
Why you shouldn’t do that:
- Anyone who overwrites
undefined
on purpose gets all that’s coming to them. undefined
is read-only in all modern browsers, and in strict mode, attempting to assign toundefined
will throw an error. This does not apply to your localundefined
variable; not a warning in sight. This is just a bug waiting to happen.
Avoid.