Coalescing Operator

Qubes 6.7

The value of the coalescing operator "??" (two question marks) is its left operand, if that operand is not "falsey" or, otherwise, its right operand.

This operator has the highest precedence.

The following values are considered to be "falsey":

  • Boolean with a "false" value
  • Number zero
  • Empty string
  • Null
  • No value

Note: These are the same values as for the "||" operator in JavaScript.

Examples

0 ?? 2 = 2
1 ?? 2 = 1
"" ?? "a" = "a"
"b" ?? "a" = "b"
0 ?? 1 + 0 ?? 2 = 3