5 ms·
They're not booleans in ruby, python, js; they're objects that can be null.
by Retra 7y ago
They're not booleans in ruby, python, js; they're objects that can be null.
- allannienhuis 7y agoThat's what !! is for!! :)
- coldtea 7y agoWhich is not really needed here. isDone will be boolean, and the other ones are still Truthy / Falsey values...
- allannienhuis 7y agoif the first term is undefined, isDone will be undefined, not false. At least in Javascript. && returns the falsy value on the left side of the expression if it evaluates to a falsy value (undefined && true) evaluates to undefined correspondingly || returns the truthy value (which might be an object) on the left hand side if evaluates truthy. That's useful for expressions like this: const a = b || 'default value'; !! turns truthy/falsy values into booleans.
- deleted 7y ago[deleted]
- coldtea 7y agoTrue, !! is still needed to get a True/False instead of the truthy/falsey value...
- coldtea 7y agonull (or None) is still a valid Falsey value, and in both examples isDone will be a boolean (strict) value, as it is the result of a boolean operation (and). So the point of the comment is moot...
- avip 7y agoNot the case in any of the abovementioned languages.
- detaro 7y agoJS: undefined && undefined -> undefined Python: None and None -> None
- Izkata 7y agoOn top of that, truthy values also propagate, so if isDelivered or isNotified are something else that's truthy (such as a 1 from mysql), isDone will not be True either and risk failing in more interesting ways down the line.