-1
需要检查的数字非空,非空。如何检查变量不为空,不为空,但零应通过javascript
但它应该通过NUMERICS像0 1 2等
var xxx=0;
if(xxx){
// for 0 not coming here
}else{
// All empty,undefined,'' should go here ---
}
需要检查的数字非空,非空。如何检查变量不为空,不为空,但零应通过javascript
但它应该通过NUMERICS像0 1 2等
var xxx=0;
if(xxx){
// for 0 not coming here
}else{
// All empty,undefined,'' should go here ---
}
你可以检查truthy或零值。
if (x || x === 0){
// 0, 1, 2, 3
} else {
// null, undefined, ''
}
检查了这一点:
function is_number(val){
if (val || val === 0){
return true;
} else {
return false;
}
}
console.log(is_number(0))
console.log(is_number(1))
console.log(is_number(null))
console.log(is_number(""))
什么是 “空” 的,为什么它比不确定的有什么不同? – h2ooooooo
'if(isFinite(xxx))' – tymeJV
'0'在JavaScript条件下被认为是'false' – Vandesh