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

# Axel Rauschmayer (6 years ago)

?? 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 withres*/.


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] strawman:default_operator