!false || !false return true?

Tell us what’s happening:
Describe your issue in detail here.

I’m not that sure about this, cant explain through my head…

the code run
/*return collection.filter(x => {
setting second loop to run each…
for(let i = 0; i < srcKey.length; i++){
here’s the issue, if is not false ||
if(!x.hasOwnProperty(srcKey[i]) || ----->if is not false … or
x[srcKey[i]] !== source[srcKey[i]] -------> if is not false

    return false. ------> both true return to false?
return true. ----- > or stop and return true?

:face_vomiting: still cant figure it out…

  **Your code so far**

function whatIsInAName(collection, source) {
let srcKey = Object.keys(source);
// Only change code below this line
  /*return collection.filter(x => {
    for(let i = 0; i < srcKey.length; i++){
      if(!x.hasOwnProperty(srcKey[i]) ||
        x[srcKey[i]] !== source[srcKey[i]]
        return false
    return true
// Only change code above this line
return collection.filter(x => {
    for(let i = 0; i < srcKey.length; i++){
        console.log("prop" + !x.hasOwnProperty(srcKey[i]))
        console.log(x[srcKey[i]] !== source     [srcKey[i]])

} return true}) 
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

Challenge: Wherefore art thou

Link to the challenge:

Sorry, but your code’s got chunks commented out everywhere, it’s hard to tell what part you’re actually working on.

I would suggest looking into the every method on the Array prototype.

1 Like

What this is saying is “if x doesn’t contain the given property or if x does have the right property, but it’s value is different…”

1 Like

correct if i’m wrong…

if(!x.hasOwnProperty(srcKey[i]) || x[srcKey[i]] !== source[srcKey[i]]

simplyfy( if (!true) or (!true) return false ) return true

if - true or false return false
if - false or true return false
if - true or true also return false

if - false or false , it run outside of the loop return true

I’m i using the right way to interpret this function?

!x.hasOwnProperty(srcKey[i]) says “take the Boolean returned by x.hasOwnProperty(srcKey[i]) and flip it.” So, if x has that property, the x.hasOwnProperty() would return true, but the ! would flip it to false.

That reads in plain English as “if x does not contain the given property…”

Now if that condition is true, that x doesn’t have that property, then the entire if statement is true. In the case of ||, the first “truthy” value renders the entire expression true.

If that condition is not met (if x does have that property), then we start evaluating after the ||:

x[srcKey[i] ] !== source[srcKey[i] ] reads as “the given property in x does not match the same property in source.” In the event they are not equal, this half of the if resolves to true… Which renders the entire expression as true.

In the case of ||, the first “true” value causes the entire expression to be true. In the case of && the first “false” value causes the entire expression to be false.


// after the or doesn't evaluate.
true || false === true
true || true === true

// the evaluation continues until the 
//  first true, but the entire expression is
//  true!
false || false || false || true === true
false || true === true

// if none are true, then the entire thing
// is false
false || false || false === false

// in the opposite way, &&
// evaluation stops at the first false
//  the second is never evaluated
false && true ===false
false && false ===false

// evaluation continues to the first false
true && false === false
true && true && true && false === false

So, in this case, if the first thing is true or the second thing is true, return false. Otherwise, return true. This only happens if both ! (NOT) conditions are true:

  • x does have the property, and
  • that property value does match.
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.