none-coalescing operator
The none-coalescing operator (??) selects a fallback only when its left operand evaluates to none.
If displayName is missing, optional chaining produces none and the expression returns "Anonymous".
How it evaluates
For left ?? right, FQL evaluates left once.
- If
leftis notnone, the expression returns it without evaluatingright. - If
leftisnone, FQL evaluates and returnsright.
The two operands may have different types. The selected operand becomes the result without conversion.
Only none selects the fallback
null represents the same absent runtime value as none, so both select the fallback. Other values remain present even when a logical operator would treat them as false.
| Left operand | Result of left ?? "fallback" |
|---|---|
none |
"fallback" |
null |
"fallback" |
false |
false |
0 |
0 |
"" |
"" |
[] |
[] |
{} |
{} |
This makes ?? useful when false, zero, or an empty value carries meaning and must not be replaced.
Coalescing and logical or
Logical or selects its right operand when the left operand is false according to FQL’s truth-value rules. ?? selects its right operand only for none.
| Value | value or "fallback" |
value ?? "fallback" |
|---|---|---|
none |
"fallback" |
"fallback" |
false |
"fallback" |
false |
0 |
"fallback" |
0 |
"" |
"fallback" |
"" |
Use or for truth-based control flow. Use ?? for an absent-value fallback.
Short-circuiting and errors
The fallback expression is evaluated only when the left operand is none.
?? does not catch runtime errors. An error from the left operand propagates before FQL can test the value:
Apply recovery first when an error should become none and then select a fallback:
See Error Handling for explicit recovery options.
Associativity and precedence
?? is right-associative. A chain groups from the right:
Logical or binds more tightly than ??, while ?? binds more tightly than the ternary operator. Parentheses can make a different grouping explicit.
See Operator Precedence for the complete order.