coalesce

Gives the first argument that is not missing. A value is missing when it is null, an unset variable, or the empty string; 0 and false are values and are kept (unlike JavaScript's `||`). When every argument is missing, the last one is returned.

Runs on: either side: the compiler places the statement that calls it where the values it uses live.

Format:

coalesce(value1, value2 [, ...])

Parameters:

Parameter Type Description
value1 mixed the value to use when it is not missing
value2 mixed the value to use otherwise
valueN mixed  [Optional]further fallbacks, tried in order

Returned Value:

Type Description
mixed the first argument that is not missing

Examples

category = coalesce(chosen_category, "all")