Optional Chaining (aka Existential Operator, Null Propagation)

Claude Pache claude.pache at gmail.com
Thu Feb 4 18:06:19 UTC 2016

> Le 4 févr. 2016 à 17:47, John Lenz <concavelenz at gmail.com> a écrit :
> [...]
> Waldemar's example makes the problem obvious but I think we could do use, which I think is preferable to the proposed:
> .?
> (?)
> [?]

Yes, that syntax is possible. Whether it is preferable is a question of taste. Personally, I don’t like it:

* I slightly prefer `?.` over `.?` for the following reason: The `?.` token may be conceptually separated in two, first the question mark which checks whether the expression at its left evaluates to null/undefined (and orders to stop processing if it is the case); then the dot which proceeds with property lookup.

* I find that the question mark inside the brackets is out of place, as it isn’t part of the arguments (for function call) or of the expression defining the key (for property access).

> [...]
> yes, I meant the equivalent to:
> x ?: value
> x == null ? x : value

I assume you meant: `x != null ? x : value`

Note that this is a completely different operator. For the proposed optional chaining operator, we stop processing when the LHS is null/undefined; while for the `?:` null-coalescing operator, it is the other way round. Also, the precedence is not the same.

I have wilfully restricted the scope of my proposal to optional chaining only, because of its intrinsic technical complexity.

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

More information about the es-discuss mailing list