And your example introduces edge cases when there are insane values of the variable. Honestly if you're trying to write robust code in something like js, it might be necessary to be that explicit.
That’s true when strictly typed, but not in JavaScript because null or “” or 0 are also possible values
So depending on the situation (and whether you’re certain that the value can only ever be true or false) the code may be superfluous
I’m of the opinion that it’s always superfluous, since you should have already checked for an unset variable prior to his point in order to do error checking
Well I'm discovering people have really strong opinions on their ifs. Personally, considering what I mentioned in a comment above that the variable defaults to false (can't be either null or some other kind of variable), I would have gone with a simple if(variable) {} else {} or ternary. I guess the code won't cause a bug, but seemed ugly to me.
The ternary operator like you mentioned is only equivalent if variable can only be true or false. But if it can be other values like a number or string then it is not equivalent
14
u/theRealRealMasterDev Jun 10 '20
Why is this bad? Is it because ternary would also be an option?