Function nullish #

Nullish coalescing operator (??). Returns the right-hand side operand when the left-hand side operand is null or undefined, and otherwise returns the left-hand side operand.

For matrices, the function is evaluated element wise.

Syntax #

math.nullish(x, y)

Parameters #

Parameter Type Description
x * First value to check
y * Fallback value

Returns #

Type Description
* Returns y when x is null or undefined, otherwise returns x

Throws #

Type | Description —- | ———–

Examples #

math.nullish(null, 42)        // returns 42
math.nullish(undefined, 42)   // returns 42
math.nullish(0, 42)           // returns 0
math.nullish(false, 42)       // returns false
math.nullish('', 42)          // returns ''

// Object property access with fallback
const obj = {foo: 7, bar: 3}
math.nullish(obj.baz, 0)      // returns 0

See also #

and, or, not

Fork me on GitHub