javascript - 为什么“真||未定义?未定义:假;” 返回“未定义”?
解决方案
条件 ( true || undefined
) 是true
,因此,三元运算符将undefined
作为结果:
const condition = true || undefined;
console.log("condition:", condition);
console.log("result:", condition ? undefined : false);
如果您的目标是除以||
:
const result = true || (undefined ? undefined : false);
console.log("result:", result);