3 ms·
The number 0 and empty strings are considered truthy, so it isn't that bad. return 0 or 42 > 0 Obviously the pattern doesn't work for checking for the ex
by cardanome 3y ago
The number 0 and empty strings are considered truthy, so it isn't that bad.
return 0 or 42
> 0
Obviously the pattern doesn't work for checking for the existence of booleans as both nil and false are falsy but you are less likely to confuse that. So yes, the ?? would help a little bit but then again, you could just explicitly check for nil.
- adbachman 3y ago> the ?? would help a little bit that's the only point of the operator. given: a = 0; b = 42; then `a or b` and `a ?? b` give two different answers, but take the same number of characters to write. > just explicitly check for nil 1. I am lazy and 2. I am explicitly checking, that's why I picked `??` not `or`