Conditionals
| Operator | Effect |
|---|---|
? : | the only branching construct |
?? | reacts only to null/undefined, not a general conditional |
? : : the only branching construct
The condition must be a boolean; the result type is the union of both branches. Ternaries nest to express ladders — indentation is free-form.
typeflow
tier: user.points >= 100 ? "gold"
: user.points >= 50 ? "silver"
: "bronze"?? : reacts only to null/undefined, not a general conditional
?? is not a general conditional — it only reacts to null/undefined, while ? : branches on any boolean.
typeflow
displayName: user.nickname ?? user.firstName
badge: user.verified ? "verified" : "unverified"Playground
Note the inferred type of tier: "gold" | "standard", not just string.
Next: Arrays.