minor fixes

This commit is contained in:
Ilya Kantor 2020-06-08 10:55:41 +03:00
parent 0e1cdaad24
commit cea9d8c9c2

View file

@ -60,11 +60,11 @@ 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 the alert shows `100`.
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So the result is `100`.
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So the alert shows the height value `0` "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.
Which behavior is better depends on a particular use case. When zero height is a valid value, then `??` is preferrable.
## Precedence