1

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  --- 
}
MPPNBD
  • 1,566
  • 4
  • 20
  • 36

2 Answers2

11

You could check for truthy or for zero value.

if (x || x === 0){
    // 0, 1, 2, 3
} else {
    // null, undefined, ''
}
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
1

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(""))