Coalesce operator
The coalesce operator is a binary operator, which looks at its left operand, and if not “falsey”, returns it, otherwise returns its right operand.
Example:
var a := b ?? c;
The above code is treated by the compiler as syntax sugar for:
var temp := b;
if temp then
a := temp
else a := c;
The left operand is evaluated only once, and the right operand is evaluated only when necessary.
You can further chain coalesce operators, for example like this:
var a := b ?? c ?? d;
At the moment QTX does not support nullable types (except for variant), so the coalesce operator behavior maps directly to JavaScript double-pipe operator (a || b).
What is a falsey value?
A “falsey” value in this case corresponds to null, unassigned, undefined, as well as type default values, ie. :
- false
- zero (0 and 0.0)
- empty string
- null
- unassigned
- undefined