Update phrasing on "Comparison with ||"

The phrase `zero becames 100.` make me think that there is a variable `zero` defined when there is not.
This commit is contained in:
Diego Torres 2020-06-06 23:18:49 -05:00 committed by GitHub
parent 020f2ea5e2
commit d90b204f78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,9 +60,9 @@ alert(height || 100); // 100
alert(height ?? 100); // 0
```
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So zero becames `100`.
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So the alert shows `100`.
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So zero remains "as is".
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So the alert shows the height value `0` "as is".
Which behavior is better depends on a particular use case. When zero height is a valid value, that we shouldn't touch, then `??` is preferrable.