函数 nullish #
Nullish 合并运算符 (??)。当左侧操作数为 null 或 undefined 时,返回右侧操作数,否则返回左侧操作数。
对于矩阵,该函数逐元素求值。
Syntax #
math.nullish(x, y)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
* | 第一个要检查的值 |
y |
* | 备用值 |
Returns #
| Type | Description |
|---|---|
| * | 当 x 为 null 或 undefined 时返回 y,否则返回 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