-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional-chained operators #1149
Labels
proposal
Proposal or discussion about a significant language feature
Comments
So if I understand correctly, the proposal is |
A couple notes:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related: #897
Here's a situation I've run into before: given an optional array, return one more than its length if it's defined, and some fallback value (e.g. 0) if it isn't. Currently this can be done in two ways:
The first one is a little verbose, especially if it's embedded in a longer expression. The second one is less obvious why it works, and doesn't easily accommodate a configurable fallback value.
C#'s mathematical operators are optional-chained by default, so this can be written as
While we can't change the behavior of the existing JS operators -- after all,
null + ''
is still meaningful -- it would be nice for there to be a syntax for this, e.g.?+
.The text was updated successfully, but these errors were encountered: