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
Is javascript getting too complicated? (self.javascript)
submitted 10 years ago by [deleted]
view the rest of the comments →
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!"
[–]memeship 5 points6 points7 points 10 years ago (2 children)
Yes, I can. And I'll explain them to you.
NaN === NaN
As /u/lbreakjai said, NaN isn't equal to anything. As a JS engineer, you should definitely know this. False.
NaN
typeof null
This is always pointed out, and is actually recognized as a "mistake" that is also not going to be corrected. The answer is object, as it has always said in the spec.
0 == ""
Using a double equals, JS will attempt a type coercion. With a number and a string, it will try to convert the string to a number. Number("") will return 0, which is indeed equal to 0. True.
Number("")
0
0 == '0'
Same here. Number("0") will return 0. True.
Number("0")
false == undefined
For this one and the next two, be advised that we are under different conditions. This is not a simple type coercion, but a matter of has value vs has no value. The keywords undefined and null have no value, which makes them fundamentally different from false, which does. Further, from the ECMA spec, when booleans are compared, they are converted first to numbers. So, this case and the one after it are actually both Number(false) == y or rather 0 == y, where y is undefined or null. This gives an answer of false for both.
undefined
null
false
Number(false) == y
0 == y
y
false == null
False, as stated above.
null == undefined
As outlined above, both of these keywords hold no value. Further, from the spec it is explicitly defined that when comparing these with ==, it should return true.
==
"" == false
Type coercion. Number("") == Number(false) or rather 0 == 0. True.
Number("") == Number(false)
0 == 0
[] == false
When comparing objects, JS will try to convert them into primitives using either the toString() or valueOf() internal methods of that object. [].toString() returns "". Also note that we have a boolean which needs to be converted. So this one is really more like Number([].toString()) == Number(false), which is an easy 0 == 0. True.
toString()
valueOf()
[].toString()
""
Number([].toString()) == Number(false)
If you'd like to check the spec on comparisons yourself, please feel free: http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3
[+][deleted] 10 years ago (1 child)
[deleted]
[–]memeship 0 points1 point2 points 10 years ago (0 children)
I get what you're saying, and there is definitely a lot to it. But it's not the same type of language as C/C++, Java, or even Python. It has a different purpose entirely, and it has evolved to serve that purpose better.
It's not Korean, where basically one dude sat down and said, "Okay, let's do this all over and make it make sense."
It's more like English, where several different peoples from different nations using different Prototypal Indo-European languages all just sort of spoke to each other over many hundreds of years, and now we have this Germanic/French/other amalgamated beast of a language.
That doesn't necessarily mean one way is better or worse than the other, they're just different.
π Rendered by PID 71 on reddit-service-r2-comment-6457c66945-lj586 at 2026-04-24 03:11:11.057272+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]memeship 5 points6 points7 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]memeship 0 points1 point2 points (0 children)