The null coalescing operator, accessed via the symbol ??
, returns the value of its left-hand operand when that value is not NULL
, and the value of it's right-hand operand otherwise.
1 ?? 2 -> 1
NULL ?? 2 -> 2
"one" ?? "two" -> "one"
NULL ?? "two" -> "two"
NULL ?? NULL -> NULL
The left-hand operand is evaluated before being being fed to the null coalescing operator. For instance, say that the left-hand operand is defined by an IF function that evaluates to NULL
after being evaluated. The null coalescing operator will return the left-hand operand:
IF(1 = 2, 3, NULL)
?? "Invalid number." -> "Invalid number."
Note that the null coalescing operator does NOT use the same evaluation criteria as the ISEMPTY function to determine if the left-hand operand is "empty". The null coalescing operator returns the right-hand operand if and only if the left-hand operand is NULL
. Empty strings and Lists, for example, are "empty", but not NULL
:
"" ?? "That's an empty string" -> ""
[ ] ?? "That's an empty List" -> [ ]