https://eslint.org/docs/rules/eqeqeq#smart
Even better is to just use TypeScript.
I imagine it is fine. If it was just myself developing I would be fine, but the insufferable junior devs that learned "=== or die" rear their ugly heads.
More equality fun in JS can be seen here: https://dorey.github.io/JavaScript-Equality-Table/
a == !a
There’s several values of a where that yields true (of the top of my head, a = '0' is one of them).Yes, you do need ===.
You need to learn the Six Falsey Things In JavaScript. Everything else when cast to boolean will be true. These six things are What and Why and When And How And Where and Who. Wait, no, that's a totally different list of six... anyways
false
undefined
null
NaN
0
"" (empty string)
That's it. Since '0' is neither when the negate operator casts it to boolean it'll become true. And then negating it becomes false. When doing a comparison between '0' and false, the standard says https://262.ecma-international.org/5.1/#sec-11.9.3
> If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
ToNumber(false) is of course 0. So you are running '0' == 0 which is visibly true...
Crucially, there's the extra step of converting '0' to a number.