我的代码基本上是这样的:
console.log(placeCost) //this returns 0 (the number, not string)
if (!placeCost || placeCost == false || placeCost == "undefined" || placeCost == '') {
console.log("no")
}
else {console.log('yes')}
结果在控制台中为“否”。为什么这解析为“真”?
尝试使用===
运算符,不要检查!var
您是否打算接受虚假参数。https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
if (placeCost === false || placeCost === "undefined" || placeCost === '') {
console.log("no")
} else {
console.log('yes')
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句