Need to check number is non null , non empty.
But it should pass numerics like 0 1 2 etc.
var xxx=0;
if(xxx){
// for 0 not coming here
}else{
// All empty,undefined,'' should go here ---
}
Need to check number is non null , non empty.
But it should pass numerics like 0 1 2 etc.
var xxx=0;
if(xxx){
// for 0 not coming here
}else{
// All empty,undefined,'' should go here ---
}
You could check for truthy or for zero value.
if (x || x === 0){
// 0, 1, 2, 3
} else {
// null, undefined, ''
}
Check this out:
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(""))