Null-coalescing default values in destructuring

Cyril Auburtin cyril.auburtin at gmail.com
Thu May 2 08:22:41 UTC 2019


Similarly to

```js
const { x = 'a' } = {}; // z === 'a'
const { y = 'a' } = { y: undefined }; // z === 'a'
const { z = 'a' } = { z: null }; // z === null
```
I'd like to propose

```js
const { x =? 'a' } = {}; // z === 'a'
const { y =? 'a' } = { y: undefined }; // z === 'a'
const { z =? 'a' } = { z: null }; // z === 'a'
```
Which would handle also null values in default cases

This is because default destructuring introduced in ES6 doesn't handle null
values, null values in JSON are quite common from APIs, it'd be convenient

It's also inspired by the null-coalescing operator
https://github.com/tc39/proposal-nullish-coalescing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190502/8b6cc7e1/attachment.html>


More information about the es-discuss mailing list