It also allows minifiers to minify that "undefined" variable. Not that i think it's good practice to use those kind of hacks that gzip compression makes obsolete :P
Re:The void of undefined in JavaScript
by moron4hire on Friday July 12, 2013 @08:20AM
(#6032178)
If you have to guard against someone doing something silly, then you are never safe. The problem is not the language at that point, it's the environment.
Re:The void of undefined in JavaScript
by MaulingMonkey on Saturday July 13, 2013 @03:41PM
(#6038481)
To err is human -- you're never safe. Even if we say people are the root of the problem, fixing their fundamentally imperfect nature is currently beyond the capabilities of science, whereas doing something like enforcing constants at a language level is not. Education will reduce, but not eliminate, the chance of making such a mistake.
https://github.com/Searle/mothello/blob/c31fc57bedd666e9da34...
I wonder if this counts as redefining undefined though!
The comment also suggests that jQuery does this, which seems to be true as explained in this link:
http://stackoverflow.com/questions/7141106/undefined-variabl...
"undefined in the jQuery code is actually an undefined parameter of a function wrapping the whole code"
Presumably if you have your own local undefined that is guaranteed to be undefined then you are safe from someone else setting it to be something silly.
Edit: The jQuery sources are all wrapped in: