ES6 doesn't need opt-in

Axel Rauschmayer axel at
Mon Jan 2 23:45:56 PST 2012

> Right. Maybe the operator should have a different name. "isDefined"? "has a value" expressed as an operator name?
>      isDefined x
> would be syntactic sugar for
>      typeof x !== "undefined" && x !== null
> The expression would not throw an exception if x hasn’t been declared.
> What about adding CoffeeScript's existential operator? It behaves in the exact same way - `x?` desugars into `typeof x !== "undefined" && x !== null`. Could be nice to have that as part of
> One more important reason to add this (whether as `x?` or as a regular operator) is that it can't be implemented in user-land code (calling it with a non-existing variable would cause a ReferenceError).


?? has been suggested by Crockford (if you include Eich’s suggestion to check for null, as well).

?? would work better than ? in JavaScript, because it wouldn’t clash with the conditional operator in JavaScript (which CoffeeScript doesn’t need, due to its functional if statement). Then the thing to add to the proposal would be ?? used as a unary postfix operator:

    if (x??) ...

Prefix might work, too.

Dr. Axel Rauschmayer
axel at


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

More information about the es-discuss mailing list