Checking value with `.hasOwnProperty` lead to undesired return value

Continuing the discussion from freeCodeCamp Challenge Guide: Check if an Object has a Property

Here is another solution that should work but does not pass the tests.

function isEveryoneHere(userObj) {
    return true
    return false


It does not work because hasOwnProperty expects a String not a Boolean expression.

1 Like

This evaluates to "Ryan"


So you’re only checking if the userObj has a Ryan property.


Interesting… I would have thought it would have been true instead of Ryan.

Yeah, one of those JavaScript quirks.

&& evaluates to its final truthy value when all operands are truthy, otherwise its first falsy value,
|| evaluates to its first truthy value when one exists, otherwise its final falsy value.

1 Like