gpt4 book ai didi

javascript - 为什么 "true || undefined ? undefined : false;"返回 "undefinied"?

转载 作者:行者123 更新时间:2023-12-01 23:27:42 25 4
gpt4 key购买 nike

我在 chrome 控制台中写了这个表达式:

true || undefined ? undefined : false;

它返回:

undefined

怎么会? enter image description here

最佳答案

条件(true || undefined)为true,因此,ternary operatorundefined 作为结果:

const condition = true || undefined;
console.log("condition:", condition);

console.log("result:", condition ? undefined : false);

如果您的目标是按 || 拆分:

const result = true || (undefined ? undefined : false);

console.log("result:", result);

关于javascript - 为什么 "true || undefined ? undefined : false;"返回 "undefinied"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66942446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com