Boolean Expression Check

Tell us what’s happening:
Why does setting the object[index] == true return falsy, while leaving out the equality return truthy? Shouldn’t they mean the same thing?

Your code so far


function truthCheck(collection, pre) {

console.log(collection.every(obj => obj[pre] == true))
console.log(collection.every(obj => obj[pre]))
return collection.every(obj => obj[pre])

}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15.

Challenge: Everything Be True

Link to the challenge:

hi @tyrossi,

even if you just pass an empty object in an if condition it will always return true.

In your case obj[pre] == true here the value of obj[pre] is matched with true and returns true only if the obj[pre] == true

whereas if you just pass an object in if condition it will give you true except if it is undefined, null , ‘’, and there might be some more you need to watch out for

1 Like

Please does it mean when you pass the code obj[ore] == false will it return false

someVariable === true will return true if and only if the value of someVariable is the boolean value true.
someVariable === false will return true if and only if the value of someVariable is the boolean value false.

If you just put someVariable in a logical operation (like an if statement) then it will be evaluated for “truthiness” or “falsyness”.

2 Likes

true only when value at obj[ore] is false

obj[pre] == false