What does values?.listArray
mean here? Specifically I am interested in the question mark.
[inputValue] = "values?.listArray"
“Question mark” or “conditional” operator in JavaScript is a ternary operator that has three operands. The expression consists of three operands: the condition, value if true and value if false.
The question mark ? in typescript is used in two ways: To mention that a particular variable is optional. To pre-check if a member variable is present for an object.
What does ?: mean in TypeScript? Using a question mark followed by a colon ( ?: ) means a property is optional. That said, a property can either have a value based on the type defined or its value can be undefined .
Double question marks(??) or nullish coalescing operator helps us to assign default values to null or undefined variables in Angular and Typescript. It's often called as Null coalescing operator. It's introduced as part of Typescript 3.7 version.
Edit
Since the original answer, Ecmascript, and Typescript (in 3.7) have both added the ?.
(called the optional chaining operator) operator. See the PR for details.
Original answer
This is not a Typescript operator. Angular 2 has a safe navigation operator in templates.
values?.listArray
is equivalent to
values != null ? values.listArray: null
More info here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With