This if statement should not detect 0; only null or empty strings

Viewed 47631

Using JavaScript, how do I NOT detect 0, but otherwise detect null or empty strings?

4 Answers

I know this might be a too late answer but it might help someone else.

If I understand you correctly you want the below statement to exclude the 0:

 if(!value) {
    //Do things
 }

I think the easiest way to do this is to write the statement like this:

if(!value && value !== 0) {
  //Do things
}

I hope this helps.

Related