pretty succinct with existing de-structuring syntax:

```
const [variable = defaultValue] =  [maybeUndefinedValue]

const fn = ({ key = defaultValue }) => {  console.log(key); }
```

> On 11 Jan 2019, at 12:00, [email protected] wrote:
> 
> Send es-discuss mailing list submissions to
>       [email protected]
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>       https://mail.mozilla.org/listinfo/es-discuss
> or, via email, send a message with subject or body 'help' to
>       [email protected]
> 
> You can reach the person managing the list at
>       [email protected]
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of es-discuss digest..."
> Today's Topics:
> 
>   1. Syntax operator for "default assignment if value doesn't
>      exits" (Sultan)
> 
> From: Sultan <[email protected]>
> Subject: Syntax operator for "default assignment if value doesn't exits"
> Date: 11 January 2019 at 10:52:12 GMT
> To: es-discuss <[email protected]>
> 
> 
> An operator syntax for the the "typeof" pattern used to detect if a 
> environment/object has a value:
> 
> if (typeof variable === 'undefined') {...}
> if (typeof object.key === 'undefined') {...}
> 
> This could manifest in destructuring as the following
> 
> var fn = ({ key ||= 1 }) => {
> }
> 
> And with variables as:
> 
> var global ||= {}
> 
> Equivalent code:
> 
> (arg) => {
>     if (typeof arg.key === 'undefined') {
>         arg.key = 1
>     }
> }
> 
> if (typeof global === 'undefined') {
> var global = {}
> }
> 
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to