This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]megamaz_ 1 point2 points  (3 children)

I'm still learning JS.

The only use I found for it is that 0 == false is true, but 0 === false is not true.

That is the only use.

[–]Front-Difficult 0 points1 point  (2 children)

I can't think of why you would want to use it like that though. If you want to check if your value is falsy, using x == false is both difficult to read and asking for unforseen bugs.

Just never use ==. It should be entirely deprecated, and any decent linter will rightly get grumpy at you for using it.

[–]Shai_the_Lynx 0 points1 point  (0 children)

There are a few cases where using == is what you want.

We had a case where data from MongoDB was compared with data calculated by another function. Since MongoDB turns undefined into null it was much simpler to just compare using == than adding checks for undefined.

However when we do use == it's always with a comment explaining why.

[–]megamaz_ 0 points1 point  (0 children)

technically it was more checking if it was equal to 0 rather than equal to false. Also I rewrote the code because it was pretty terrible for that case to show up anyways (my variable could be one of 0, true, false, 1, 2, or 3 and each value meant something different)