Proposing a conditional assignment (or equals) operator

Claude Pache claude.pache at
Tue May 10 08:21:49 UTC 2016

> Le 10 mai 2016 à 09:44, G. Kay Lee <balancetraveller+es-discuss at> a écrit :
> Can't remember any instance where I've written something like `x = x || {}` after the introduction of Default Parameters in ES6, so I don't see any chance for me writing something like `x ||= {}` even if this thing somehow makes its way in.

Some people do have use cases despite default arguments, see e.g. <>

> The thing is, it's far more common to encounter codes like `x = y || {}`, and then a new Default Operator would make sense due to the issue with falsy values. So I'd throw my support behind an authentic Default Operator proposal like `x = y ?? {}` ( <>). But definitely not `||=`.

Agree. I wonder why people keep to reclaim a `||=` operator (with semantics inspired from binary `||`), when their use cases generally show that `??=` is more appropriate (with approximate semantics of: `if (a === undefined) a = b;`).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list