gpt4 book ai didi

javascript - 检查 JavaScript 中除零之外是否为假

转载 作者:行者123 更新时间:2023-12-03 00:08:39 26 4
gpt4 key购买 nike

我正在检查一个值是否不为假

if (value) {
..
}

但我确实想接受零作为(非虚假)值。这通常是如何完成的?难道是

if (value || value === 0) {
..
}

还是什么?

最佳答案

if (value || value === 0) {
..
}

更干净的方式,没问题。

只是为了好玩,试试这个

val = 0;
if(val){
console.log(val)
}
//outputs 0 **update - it used to be.. but now it seems it doesnt in chrome

还有

var val = 0;
if(val){
console.log(val)
}
//outputs nothing

关于javascript - 检查 JavaScript 中除零之外是否为假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31626876/

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