(no title)
timoxley | 8 years ago
e.g.
const check(cond) => cond && otherValue
If `cond` is falsey, it returns `cond`.This means the function could return any of: `false`, `undefined`, `null`, '', `0` or `NaN`.
This is a fairly common issue I see with React + JSX:
<div>{cond && <SomeComponent />}</div>
If `cond` is `false`, `null`, `undefined` or '', everything will be just fine, but if `cond` happens to be a zero or `NaN`, suddenly you have a weird `0` or `NaN` rendering in your page. Oops.Low cost, much safer guard:
const check(cond) => !!cond && otherValue
sergeykish|8 years ago
Same behavior on Ruby:
Waterluvian|8 years ago
acjohnson55|8 years ago
That's the problem with antipatterns. It's impossible to remain alert to the edge cases, and then they eventually bite you in production. Better to lint them away. But it's difficult to convince people not to do something really convenient if they haven't gotten bitten yet.
sgustard|8 years ago