我刚刚在控制台中执行了以下命令:
typeof false || undefined // "boolean"
虽然我期望它返回“未定义”,但因为
typeof undefined // "undefined"
为什么它返回“ bool 值”?如果先前的计算结果为假值,OR
运算符是否应该返回最后一个参数?所以 false || undefined
返回 undefined
并且针对 undefined
执行 typeof
?
最佳答案
您没有遵守运算符优先级!
> typeof false || boolean // (typeof false) || boolean
"boolean"
> typeof (false || boolean)
"undefined"
关于javascript - 为什么 `typeof false || undefined` 返回 "boolean",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39658310/