Profile Lookup, Alternate Solution Confusion

Tell us what’s happening:
I’ve tried 2 different solutions:

Solution 1.

for (var x = 0; x < contacts.length; x++){
     if (contacts[x].firstName === name) {
       if (contacts[x][prop]) {
            return contacts[x][prop];  } 
       else {   return "No such property";   }
          }
      }
return "No such contact";

Solution 2.
(The one given in guide)

for (var x = 0; x < contacts.length; x++){
   if (contacts[x].firstName === name) {
       if (contacts[x].hasOwnProperty(prop)) {
           return contacts[x][prop];
       } else {
           return "No such property";
       }
   }
}
return "No such contact";

They both work. The only difference is the second if statement:

  1. if (contacts[x][prop])
    2.if (contacts[x].hasOwnProperty(prop))

Why does the if statement for Solution 1 work. Does it return a Boolean instead of the property?

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/

First of all, make sure you are formatting your code in the editor. It makes it really difficult to read without it.

They both return booleans. That’s why statements inside curly brackets get executed. Often you will get the same result with or without hasOwnProperty. The latter ignores properties that are inherited.

You could read more here.

I tried formatting it correctly it change after submitting it for some reason. I am going to take a look at the article. Thanks!

After reading the above article. I am still confused why contacts[x][prop] returns a Boolean in an if statement and a value elsewhere (such as the following return statement).

Thanks! This breakdown really helpls!!!