Skip to main content
Version: v4.24

otherwise

Returns a fallback value if primary is null.

otherwise(primary:any, fallback:any) -> any

Description

The otherwise function evaluates its arguments and replaces primary with fallback where primary would be null.

primary: any

The expression to return if not null.

fallback: any

The expression to return if primary evaluates to null. It must have the same type as primary.

Examples

Set a default value for a key

from [
  {x: 1},
  {x: 2},
  {}
]
x = x.otherwise(-1)
{x: 1}
{x: 2}
{x: -1}