Re:Why does parseInt(1/0, 19) return 18?
by chris_wot on Tuesday July 10, 2012 @03:04AM
(#4222509)
I'm unclear what in particular is such a mess about Javascript?
[ Parent
| on HN ]
Re:Why does parseInt(1/0, 19) return 18?
by prodigal_erik on Tuesday July 10, 2012 @04:18AM
(#4222650)
Javascript's maze of type coercion rules produce results which manage to be frequently wrong but in ever more bewildering ways only slightly less crackheaded than PHP. It's also saddled with Java's inexcusable "everything is an object, except for all the crap that isn't" philosophy. http://wtfjs.com/ is a growing list, but a few of my favorites:
[] != []
[] == ![]
{} + [] is 0
[] + {} is "[object Object]"
{} + {} is NaN
Re:Why does parseInt(1/0, 19) return 18?
by lifthrasiir on Tuesday July 10, 2012 @04:46AM
(#4222700)
To be exact, {} + {} is NaN only when used as a statement. In fact it is equivalent to {}; +{} which results in the last statement being evaluated as NaN. When you put parentheses around it (e.g. ({}+{})) it evaluates to "[object Object][object Object]", which should be obvious from [] + {} if it were indeed obvious.
Yeah, the people talking about this are talking about it due to a five-minute lightning talk, and honestly it really bothers me that he is making people think that adding two objects together has that behavior when in fact it has nothing to do with objects at all: it has much more to do with automatic semi-colon insertion than with scary type conversion.
Clearly my comment has annoyed someone. I'm actually quite serious though; rather than voting me down, perhaps an answer (or even just a link!) would be more useful to the discussion at hand.
Re:Why does parseInt(1/0, 19) return 18?
by Androsynth on Tuesday July 10, 2012 @03:39AM
(#4222568)
Everything other than http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockfor...
I have not read the book, but I'm told that (despite being only 176 pages) half of that book actually talks about language flaws and bad parts and only half of the book is actually about the good parts. Again, have not read it, just what I was told.
Re:Why does parseInt(1/0, 19) return 18?
by mattdeboard on Tuesday July 10, 2012 @04:47AM
(#4222701)
There is are a couple appendices at the end that discuss the truly terrible and the simply bad-but-work-aroundable parts. Most of it is discusses the subset of the language that is powerful and expressive. He starts the book off by saying "Javascript is a steaming pile of good intentions" which pretty much sets the tone for the rest of the book.
You should read it. It IS very short and can be read in one sitting. Then you wouldn't be left to trust the word of others.