Alwaysblue
Alwaysblue

Reputation: 11830

if condition being executed even when conditions aren't meet

I am working on React-native and for some reason I think my programme is running body of if-statement even when conditions aren't fulfilled

So this is what I have

  if (!this.props.exhangeSort && !this.props.exchangeError) {
            console.log(this.props.exchangeSort) //Line 72
            console.log(this.props.exchangeError) //Line 73

Here I am using && and so I am expecting it to run when both this.props.exhangeSort and this.props.exchangeErrorare false

But when I check my console.logafter it throws an error

I am seeing the response from line 72 to be True and from Line 73 to false

Question: Since response from Line 72 is True, Shouldn't it not run/log/go through the body of if-statement?

enter image description here

Upvotes: 0

Views: 171

Answers (1)

Aviral Mansingka
Aviral Mansingka

Reputation: 46

I would recommend taking a look at the conditions in line 71 again. There might be a typo in !this.props.exhangeSort when you probably meant !this.props.exchangeSort. If the property doesn't exist javascript might be returning an undefined which is javascript false-y.

Upvotes: 3

Related Questions