Syntax operator for "default assignment if value doesn't exits"

Sultan thysultan at gmail.com
Fri Jan 11 10:52:12 UTC 2019


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 = {}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190111/644104c0/attachment.html>


More information about the es-discuss mailing list