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.
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.
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.
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.