Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Add an example involving nullish-coalescing
Browse files Browse the repository at this point in the history
Closes #30
  • Loading branch information
claudepache committed Jun 11, 2019
1 parent 0e4ec6b commit 5e994a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ var street = user.address?.street
var fooValue = myForm.querySelector('input[name=foo]')?.value
```
When some other value than `undefined` is desired for the missing case, this can usually be handled with the [Nullish coalescing operator](//github.com/tc39/proposal-nullish-coalescing):
```javascript
// falls back to a default value when response.setting is missing or nullish
// (response.settings == null) or when respsonse.setting.animationDuration is missing
// or nullish (response.settings.animationDuration == null)
const animationDuration = response.settings?.animationDuration ?? 300;

```
The call variant of Optional Chaining is useful for dealing with interfaces that have optional methods:
```js
Expand Down

0 comments on commit 5e994a3

Please sign in to comment.