?? operator (was: ES6 doesn't need opt-in)

Axel Rauschmayer axel at rauschma.de
Tue Jan 3 00:57:26 PST 2012

> ?? would work better than ? in JavaScript, because it wouldn’t clash with the conditional operator in JavaScript
> Wouldn't it be possible to use a single '?' for all of them (the conditional, default and existential operators) and disambiguate between them according to the way they're used? It seems to me like their syntax is different enough to allow it - the default operator would have no `: ElseExpression` following it and the existential operator is not followed by anything.

I don’t think it would be worth it. You’d save one character and it would still be confusing to humans.

> Also, should they be allowed on all expressions or just identifiers? It would be quite useful on arbitrary expression, like `func() ?? default` or `if ( (res = func())? ) /* do more stuff with `res` */`.


> P.S. Are CoffeeScript's `func? arg` and `obj?.prop` too extreme?

The former is part of Crockford’s proposal [1]. The latter is very useful indeed.

[1] http://wiki.ecmascript.org/doku.php?id=strawman:default_operator

Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120103/d95a6f47/attachment-0001.html>

More information about the es-discuss mailing list