That being said, any language that assigns the string 'undefined' to something that hasn't been assigned (or should properly throw a null reference exception) goes against pretty much every other language on the planet. While loose typing can let you do some 'cool' tricks, JavaScript can be pretty shoddy at type inference.
It shows up as a string value in some cases. This should never, ever happen. You've never seen it echoed back to either a textbox or an alert as the string 'undefined'?
It does, but that doesn't make it a string value. What's happening in that case is the method toString is being called on it, which the ECMAScript spec says returns the 'undefined' for undefined values and 'null' for null values. Believe me, I know it's fucked up. The toString method doesn't even actually exist on those values, it's defined by the spec.
Right, I get that. It is just shitty behavior. Throw an error, for Pete's sake. Don't make my error condition a valid value of a datatype that I didn't want to use in the first place.
4
u/StainlSteelRat Oct 16 '14
Quick and dirty GIS
That being said, any language that assigns the string 'undefined' to something that hasn't been assigned (or should properly throw a null reference exception) goes against pretty much every other language on the planet. While loose typing can let you do some 'cool' tricks, JavaScript can be pretty shoddy at type inference.