News for hackers. Stuff that matters.
Re:John Resig: Redefining the Introduction to Computer Scien... by esrauch on Tuesday August 14, 2012 @06:30PM (#4383402)
Tangent: to be clear, there is no difference between []+{} and {}+[] in javascript.

var a = {} + [];

var b = [] + {};

var c = String({}) + String([])

All three are equal. The order does matter in general because its doing string concatenation which obviously matters ([1] + [2] == "12"), but the fact that js always does string coercion and concatenation anytime you have + without numbers on both side isn't really that crazy.

Re:John Resig: Redefining the Introduction to Computer Scien... by ehsanu1 on Tuesday August 14, 2012 @06:44PM (#4383466)
Type coercion is crazy, if for no reason other than making the behavior of certain code harder to predict. That said, I don't think it's a major stumbling block, and once you learn to avoid relying on it there's no problem.

There are plenty of parts of JavaScript like that, but these gotchas are just red herrings. The core language is great.

Re:John Resig: Redefining the Introduction to Computer Scien... by ghusbands on Friday August 17, 2012 @02:10PM (#4397834)
There is a slight difference between []+{} and {}+[], in fact, but you're unlikely to see it outside of a console. At a console, {}+[] gives you 0, which is different to the result you get above. That's because it's an empty block followed by +[].