我们可以在js中编写这样的代码来检查条件
input != (null || undefined) ? document.write(input) : document.write("Not Found");
我希望检查输入是否为空或未定义
最佳答案
你的做法不对
input != (null || undefined)
这将始终被视为
input != undefined
因为||
逻辑或总是返回第一个真值(如果有的话),而不是返回最后一个值
你可以这样做
input != null || input != undefined
或者你可以
[null,undefined].some(val => val != input)
关于javascript - 我们可以在单个三元条件下检查多个值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56911143/