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
undefinedon purpose gets all that’s coming to them. undefinedis read-only in all modern browsers, and in strict mode, attempting to assign toundefinedwill throw an error. This does not apply to your localundefinedvariable; not a warning in sight. This is just a bug waiting to happen.
Avoid.