5
u/Heavy_Hole Jul 17 '21
I never use the double equal operator, why would any want to? The triple equal operator is way better because it does strict equivalence. Use typeof if you are trying to determine the data type. Honestly unless I was debugging or reading someone's code I would never have to know a thing about the loose double equal sign. And to tell you the truth I would either rewrite what I saw or just walk away from the codebase because that coder either doesn't give a shit or has terrible preferences for what is considered good practice. For anyone learning JS stay away from the double equal operator and use the stricter triple equal operator. It WILL introduce bugs into your code because of its loose equivalency.
2
Jul 17 '21
Agreed, I’m very new but I remember a situation where I could have easily used double equals to compare a string with a number inside the double quotes, but instead used triple equals and compared it to Number() and then the value I was plugging in for comparison just because I disliked double equals so much…it was more verbose but it just didn’t feel right exploiting one of JS’s strange logical anomalies.
3
u/inabahare Jul 17 '21
At my workplace we have linter rules agains == and youre doing gods work avoiding it!
2
u/Heavy_Hole Jul 17 '21
You made the right move, because what happens when something else passes through, let's say you where checking to see if it was equal to zero and false got passed through, that would be true since the boolean false you pass would be converted to a 0. Double equals introduces lots of opportunities for bugs.
2
2
Jul 18 '21
Also logically, its not a good idea to use nulls in place of 0s. 0 is a known quantity, where as null is simply unknown.
I've seen where people default to 0s on isnull in sql, then average it out on the front end and wonder why its all fucked up, instead of filtering those nulls out either in te query or using a simple filter function in js..




11
u/senocular Jul 17 '21
This is not entirely true. In some cases both values are converted, for example with string-boolean comparisons. In that case both are converted to numbers.
There's also an exception with undefined/null comparisons: