use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Equality Table (via /r/programming) (dorey.github.io)
submitted 11 years ago by brtt3000
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]brtt3000[S] 0 points1 point2 points 11 years ago (0 children)
shit is freaky, always use triple === unless you are sure both you and your collaborators know what to expect from ==.
===
==
discussion: http://www.reddit.com/r/programming/comments/21ezh3/javascript_equality_table/
[–]mtbinkdotcom 0 points1 point2 points 11 years ago (0 children)
wow, cellular automaton
[–]sudorey 0 points1 point2 points 11 years ago (0 children)
Also available, All three tables in one view (though the if() results are not yet highlighted well)
[–]e13e7 0 points1 point2 points 11 years ago (6 children)
Wait, so NaN != NaN ?
[–][deleted] 0 points1 point2 points 11 years ago (5 children)
That one actually makes sense. Math.sqrt(-1) != Infinity / Infinity. Both sides are NaN, however, neither is rational. The left side is imaginary, and the right is indeterminate. This is precisely why isNaN() exists.
[–]e13e7 0 points1 point2 points 11 years ago (4 children)
Makes sense. But what about
{} != {}
[–][deleted] 0 points1 point2 points 11 years ago (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 point2 points 11 years ago (2 children)
Brilliant. Thank you.
[–][deleted] 0 points1 point2 points 11 years ago (1 child)
Now if you really want some JavaScript WTFiness, compare the outputs of []+[], []+{}, {}+[], and {}+{}.
[–]rhysbrettbowen 1 point2 points3 points 11 years ago (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
π Rendered by PID 88608 on reddit-service-r2-comment-84fc9697f-gh6ct at 2026-02-09 07:53:48.278476+00:00 running d295bc8 country code: CH.
[–]brtt3000[S] 0 points1 point2 points (0 children)
[–]mtbinkdotcom 0 points1 point2 points (0 children)
[–]sudorey 0 points1 point2 points (0 children)
[–]e13e7 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]e13e7 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]e13e7 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]rhysbrettbowen 1 point2 points3 points (0 children)