I keep a little list of these by my desk for my own sick amusement (which is something that my pal oxguin reckons is not a fact to be shared
out loud). If you like this little lot, then you would probably enjoy some of the prior art at wtfjs.
Let’s start by making x an array with 0 in it.
It should equal itself, which is good.
trueBut it also equals not itself, which is not so good.
trueWhat about comparing a 3 element array and a string?
The type of not a number is, well, a number. Sensible.
js> typeof NaN
"number"Well at least that means it ought to be equal to itself, right?
falseSo much for NaN. I wonder what the type of null is …
js> typeof null
"object"… but of course it is not actually an instanceof Object
js>null instanceof Object
falseSo, what is a string then?
js> "string" instanceof String
How about a really big number first of all. Wait. What?
10000000000000000Hopefully small numbers make more sense.
falseI guess not. I bet that max is still bigger than min though.
Calling + on an empty array and an empty array gives the empty string. Who knew?
""How about an empty array and an empty object?
"[object Object]"An empty object and an empty array gives, ummm, 0.
0Whereas an empty object and an empty object is not a number. Which is true, I suppose.
I’ve heard of that boolean arithmetic. Let’s give it a try.
trueAh. It looks like true is equal to one. I’ll just check.
And one for luck
See if you can work out what this will evaluate to
Incidentally, these were all evaluated on spidermonkey 24.2.0. Maybe they won’t work in node/whatever other js engine you are using…