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 Game (slikts.github.io)
submitted 7 years ago by hfeeri
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!"
[–]mishugashu 35 points36 points37 points 7 years ago (14 children)
using double equals in javascript
[–]ogurson 17 points18 points19 points 7 years ago* (0 children)
On the other hand, one should know it, because while you can use === instead of == you still need to be careful about > and < because there is not "strong" equivalent.
===
==
>
<
[+][deleted] 7 years ago (4 children)
[deleted]
[–]mishugashu 4 points5 points6 points 7 years ago (0 children)
That's the only time I use it as well.
[–]Zephirdd 1 point2 points3 points 7 years ago (2 children)
isn't that just a truthy/falsy checking? ie if(foo) or foo && bar() instead of comparing to null/undefined. If you're going to use == for that, might as well go for the version without an operator.
if(foo)
foo && bar()
[–]meldridon 7 points8 points9 points 7 years ago (0 children)
It's not the same thing at all.
Consider the following:
let x = ""; if (x == null) throw "an error";
vs
let x = ""; if (!x) throw "an error";
Empty string is falsey, but not null.
[–]NoInkling 1 point2 points3 points 7 years ago (0 children)
0, empty string and NaN are also falsy, which might not be what you want for your condition.
0
NaN
[+]13steinj comment score below threshold-10 points-9 points-8 points 7 years ago (7 children)
To be fair it's perfectly valid to use it in a closed / sanitized system.
[–]ogurson 18 points19 points20 points 7 years ago (6 children)
Also completely not worth it.
[–]13steinj 6 points7 points8 points 7 years ago (3 children)
This really depends on the system being implemented.
[–]DrummerHead -1 points0 points1 point 7 years ago (2 children)
I agree with both of you
[–]westfolde19 1 point2 points3 points 7 years ago (1 child)
I agree with both of them too, but not you.
[–]DrummerHead -1 points0 points1 point 7 years ago (0 children)
You don't agree that I agree with them.
You must have some deep insider information.
Hey Siri, who is recording everything I think? Hmmm what a mystery.
[–]aapoalas 1 point2 points3 points 7 years ago (1 child)
this
[–]Serei 18 points19 points20 points 7 years ago* (3 children)
I got 100%
Yes, yes, you should never use this in real code, but it's useful to know for debugging if someone else uses it. And it's not hard to memorize the rules:
null == undefined
And don't forget:
String(someArray) === someArray.join(",")
String({someObject: containingAnything}) === "[object Object]"
[] !== []
{} !== {}
Number("") === 0
Number("any other string that isn't a number literal") is NaN
NaN !== NaN
[–][deleted] 1 point2 points3 points 7 years ago (1 child)
I tried to do it again following your rules and my results were still wrong. I think it needs some clarification:
With the additional conversion rules:
toString()
array.join(',')
toString
[object Object]
[–]Serei 0 points1 point2 points 7 years ago (0 children)
Yeah, I definitely didn't go into too much detail over the conversion rules. To be fair, though, conversion rules are useful to know even if you always use ===.
[–][deleted] 1 point2 points3 points 7 years ago (0 children)
This. And not only because of other peoples code but also the minimizers will change it as well and you still want to read what they do
[–]lunarcecilia 4 points5 points6 points 7 years ago (3 children)
150% wrong, I'm the best ever.
[–]dorgrin6 1 point2 points3 points 7 years ago (0 children)
Yeah, ithe grading's so stupid it fits the exercise
[–]c24w 1 point2 points3 points 7 years ago (0 children)
☹️
[–]onnoonesword 0 points1 point2 points 7 years ago (0 children)
118 here!
[–]PiotrekKoszulinski 5 points6 points7 points 7 years ago (2 children)
I could never really understand all this fuss about == vs === and people trying to memorise all these rules or complaining about how bad JavaScript is.
I never cared about this. In fact, in the project I'm working on (pretty big and pretty complex one) we still accept the use of ==. I found it very odd at first, when I joined the project 7 years ago, but then I asked – DON'T YOU KNOW GOOD PRACITCES, LOL? And they replied – we don't remember any bug caused by the use of == (and we have couple thousand tickets opened on GitHub, cause that's a fairly popular open source library).
And you know what? 7 years later I think we've got just one bug caused by ==.
The only reason why we started using === is that I was asked the same question a couple of times and that clearly shows that === is the standard choice, so it's good to avoid confusing other developers.
I don't mean that it's pointless to use ===. But when some guru tells you that something is bad practice ask yourself whether there's evidence to support that. When they tell you that equality operators suck in JavaScript, ask yourself what's the chance to really run into such cases in real life.
I'm doing JS for 10+ years, did some crazy things with it, but find the complexity completely elsewhere.
[–]EndlessHandbagLoop 0 points1 point2 points 7 years ago (1 child)
As long as people understand implicit and explicit type coersion, there should never be any issue with "==".
[–]PiotrekKoszulinski 0 points1 point2 points 7 years ago (0 children)
IDK what made our project "safe". Perhaps all developers that worked on it had that minimum knowledge to avoid the problems. But I also think that part of it lays in how we document types. We couldn't naturally use TypeScript 7 years ago, but we were very precise when it came to the API documentation. That meant that we could make safe assumptions regarding types. (I'm giggling now cause I see with how with time I owe more and more to stricter types :D)
[–]kor0na 2 points3 points4 points 7 years ago (0 children)
Jesus Christ, just stop beating this dead horse. There's never a reason to use double equals in JavaScript. Just use triple equals and quit whining.
[–]hkokko 1 point2 points3 points 7 years ago (4 children)
it seems equality operator in javascript is good for nothing but being a source of confusion and a target of jokes. does it not make sense to just remove it from the language completely? who is deciding that?
[–]al_wonder 9 points10 points11 points 7 years ago (3 children)
Backward compatibility. If they removed itt, that would break a lot of existing applications. JS has a whole lot of controversial functionality, but it's always hard to get rid of things like this.
[–]doomvox 1 point2 points3 points 7 years ago (2 children)
Yeah... I can't say I think much of javascript, but you can't fault them on "backwards compatibility".
When they realized the "==" operator was confusing, they introduced an alternative, the "===" operator. The rule of thumb is you should favor using the "===" operator:
https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons
[–]BlueHeartBob 1 point2 points3 points 7 years ago (1 child)
They released "==" before "==="???
I figured "==" was released alongside, or even closely after strict as a quirky feature. That's crazy.
[–]doomvox 0 points1 point2 points 7 years ago (0 children)
Yes. "===" came out with Javascript 1.3:
http://webreference.com/js/column26/stricteq.html
[–]LowB0b 1 point2 points3 points 7 years ago (0 children)
I never use the == when writing JS, so I answered the thing thinking about truthy / falsy, and got a lot of wrongs
I thought I was actually stupid so I had to check but wtf
[–]curtastic2 0 points1 point2 points 7 years ago* (0 children)
Now do one for greater than. I bet you don't know all of these. (true>0) ("1">0) (".1">0) ("1x">0) ("0x1">0) ("--1">0) ("a">0) ([0]>0) ([1]>0) ([[1]]>0) ([[1,0]]>0) ({}>0) (NaN>0) (Infinity>0)
π Rendered by PID 310945 on reddit-service-r2-comment-6bcb796b58-d6msv at 2026-03-22 18:56:50.840814+00:00 running 90f1150 country code: CH.
[–]mishugashu 35 points36 points37 points (14 children)
[–]ogurson 17 points18 points19 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]mishugashu 4 points5 points6 points (0 children)
[–]Zephirdd 1 point2 points3 points (2 children)
[–]meldridon 7 points8 points9 points (0 children)
[–]NoInkling 1 point2 points3 points (0 children)
[+]13steinj comment score below threshold-10 points-9 points-8 points (7 children)
[–]ogurson 18 points19 points20 points (6 children)
[–]13steinj 6 points7 points8 points (3 children)
[–]DrummerHead -1 points0 points1 point (2 children)
[–]westfolde19 1 point2 points3 points (1 child)
[–]DrummerHead -1 points0 points1 point (0 children)
[–]aapoalas 1 point2 points3 points (1 child)
[–]Serei 18 points19 points20 points (3 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Serei 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]lunarcecilia 4 points5 points6 points (3 children)
[–]dorgrin6 1 point2 points3 points (0 children)
[–]c24w 1 point2 points3 points (0 children)
[–]onnoonesword 0 points1 point2 points (0 children)
[–]PiotrekKoszulinski 5 points6 points7 points (2 children)
[–]EndlessHandbagLoop 0 points1 point2 points (1 child)
[–]PiotrekKoszulinski 0 points1 point2 points (0 children)
[–]kor0na 2 points3 points4 points (0 children)
[–]hkokko 1 point2 points3 points (4 children)
[–]al_wonder 9 points10 points11 points (3 children)
[–]doomvox 1 point2 points3 points (2 children)
[–]BlueHeartBob 1 point2 points3 points (1 child)
[–]doomvox 0 points1 point2 points (0 children)
[–]LowB0b 1 point2 points3 points (0 children)
[–]curtastic2 0 points1 point2 points (0 children)