即使条件为真,条件条件也会跳转到else-if语句

I am doing a challenge on FreeCodeCamp. My goal is to check whether name is an actual contact's firstName and the given property (prop) is a property of that contact.

The problem I am facing is that in the first picture the if-statement comparison name === contacts[i][prop] (contacts is the name of the array in which the objects I am looping over are located) returns true and the name gets logged, so everything is fine. Also notice here: the first else-if statement compares name === contacts[i][prop], this changes in the second picture.

But if I change the first else-if statement to name !== contacts[i][prop], as you can see in the second picture, the first else-if statement gets executed, even tho I did not change the if-statement at all. Why is that.?

评论