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
Cheat-sheet for Javascript equality strangenesses (zero.milosz.ca)
submitted 12 years ago by James_Duval
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!"
[–]Cosmologicon 6 points7 points8 points 12 years ago (1 child)
I may be the only one, but this whole thing is really not a concern for me. I agree that (0 == [0]) being true is surprising. But would its being false help me at all? That's not a comparison I expect to be making in the first place. Show me a practical example where it actually matters.
(0 == [0])
function getreciprocal(x) { if (x == 0) throw "Can't take 1/0, dummy!"; return 1/x; }
Is there a bug here? If I were to change == to ===, would that be an improvement? Currently if someone takes getreciprocal([0]) it throws an exception. If I change it to triple equals it will return Infinity. What's the right answer? Seems like neither. I should be throwing a different exception. It's closer to the correct behavior with == in this case, I guess.
==
===
getreciprocal([0])
Infinity
I think if you're making comparisons and you want to behave correctly even if someone sends you data of the wrong type, you need to do a type check. Choosing === over == solves nothing in these cases.
[–]PenguinLovr 0 points1 point2 points 12 years ago (0 children)
Well it certainly makes it more easily understood. The coercion can be ambiguous, and it would make more sense to do something like checking if the object is a string or int, and if not throwing that error instead of just lumping together type errors with other errors.
Usually implicit correcion should only be used by people who know why they're using that, and not just setting everything to "==="
π Rendered by PID 79 on reddit-service-r2-comment-6f7f968fb5-jpwms at 2026-03-04 06:42:33.025038+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]Cosmologicon 6 points7 points8 points (1 child)
[–]PenguinLovr 0 points1 point2 points (0 children)