-1

I have below set of code -

if(!obj.Substance){
 ...Some Code...
}

In this condition Substance variable is of string type.

I want to check on which condition code will enter within if block? I tried setting Substance value as undefined , blank = empty string also tried to put some value. But code did not entered in if block.

C Sharper
  • 8,284
  • 26
  • 88
  • 151

1 Answers1

1

The code will only enter the if block if the obj.Substance variable is falsey.

The following values are falsey:

  • false
  • 0
  • "" (empty string)
  • null
  • undefined
  • NaN

So, if obj.Substance is any of those values, the code will enter the if block.

Igor
  • 474
  • 2
  • 10