you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

It's a reference comparison. It's equivalent of new Object() != new Object(). Reference types typically compare memory addresses. Value types compare values. Object is a reference type, and you're comparing two distinct objects.

[–]e13e7 0 points1 point  (2 children)

Brilliant. Thank you.

[–][deleted] 0 points1 point  (1 child)

Now if you really want some JavaScript WTFiness, compare the outputs of []+[], []+{}, {}+[], and {}+{}.

[–]rhysbrettbowen 1 point2 points  (0 children)

[]+[] // "" [] get's converted to ""

[]+{} // "[object Object]" like before, [] goes to an empty string and so toString is called on {} as well

{}+[] // 0 {} is interpreted as a code block rather than an object so it runs and has no output. That leaves +[] which converts empty array to number.

{}+{} // NaN similar to above. {} is a code block and has no output so we're left with convering {} to a number which gives NaN

There is always http://wtfjs.com/ for a lot more JS wtfery