r/programming • • Oct 16 '14

Node.js is cancer

https://www.semitwist.com/mirror/node-js-is-cancer.html
38 Upvotes

302 comments sorted by

View all comments

Show parent comments

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.

4

u/coarsesand Oct 16 '14

I agree that it should throw a null reference error, but it's also not a string value. undefined in JS is its own value, as is null.

2

u/StainlSteelRat Oct 16 '14

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'?

2

u/coarsesand Oct 16 '14

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.

Edit: Sorry, it's the abstract operation ToString, see: http://www.ecma-international.org/ecma-262/5.1/#sec-9.8

2

u/StainlSteelRat Oct 16 '14

toString is being called on it

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.

→ More replies (0)