Ok, so apparently the following is valid JavaScript:
var undefined = "blah";
Yes, you’ve read that right. What I’m doing there is redefining the undefined
symbol to “blah”.
I learned fromĀ Angus Croll that this is something ECMA added to ECMA 3. Presumably, in earlier versions you could not do something as pants-on-head stupid as this but someone someone thought that adding this capability would be an improvement. How did that work exactly? “Hey! JavaScript is not sucky enough. Let’s allow undefined
to be redefined to arbitrary values.”
Here’s how an intelligently designed language handles this kind of nonsense:
$ python Python 2.7.4 (default, Jul 5 2013, 08:21:57) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> None = "blah" File "", line 1 SyntaxError: cannot assign to None >>>
Angus points out that ECMA 5 disallows assignments to undefined
so I guess one of the ECMA luminaries had an epiphany.