Ternary Conditional
The ternary operator evaluates a condition and returns one of two values. It is right-associative.
condition ? trueExpression : falseExpression
var status = Data.active ? "on" : "off"
Nesting
Ternary expressions can be nested for multi-way selection:
var grade = score >= 90 ? "A" : score >= 80 ? "B" : "C"
Right-associativity means the above is parsed as:
var grade = score >= 90 ? "A" : (score >= 80 ? "B" : "C")
Short-Circuit Evaluation
Only the selected branch is evaluated. The other branch is not executed:
var result = count > 0 ? total / count : 0 # No division-by-zero risk