Home > other >  is there a short way to write ? value !== null
is there a short way to write ? value !== null

Time:10-05

I have value !== null

I need to get false in null case but 0 is true. is there a short way to write?

!!value or Boolean(value) not works for me.

CodePudding user response:

You can use != instead of !== if you also want to return false for the input undefined. And you can omit the spaces around the operator:

value!=null

Short of a helper function isNull(…), it won't get any shorter. There is no special "null test" unary operator, if that is what you were looking for.

  • Related