Re:JavaScript Equality Minesweeper
by kenbellows on Monday September 17, 2018 @12:58PM
(#18007674)
In that sort of case I like to use explicit type casting, e.g.
if (Number(myNum) === 2) {}
For me this also extends to using `Boolean(val)` instead of `!!val`, etc.; though I understand the appeal of those nifty one-liners, I think they cause confusion in many places and don't communicate intent nearly as well.
if (myNum === 2 || myNum === '2') {}
It's very easy for developers to mistakenly "see" the third equality symbol and get confused by the intent of the code.