The coalesce binary expression evaluates to the first non-nil value. There is an augmented assignment version of it as well.
| Grammar |
| <a> ? <b> |
The expression evaluates to a unless that value is nil, in which case, it evaluates to b.
Although uncommon, nothing prevents b itself from also being nil. Neither expression will be evaluated more than once and if a is non-nil then b will not be evaluated at all.
The type of the coalesce expression is the greatest common denominator between the type of a and the type of b.
| Grammar |
| <a> ?= <b> |
In the augmented assignment version, the result is assigned back to a. This requires that b is type compatible with a or a compilation error will occur.