Diff Two Arrays differences between FCC and others consoles

Tell us what’s happening:
I can’t understand why my code works in Chrome and in the Eloquent Javascript sandbox but not here. Could someone explain it, please?

Your code so far


function diffArray(arr1, arr2) {
  var newArr = [];
  for (i of arr1){
    if (!arr2.includes(i)){
      newArr.push(i)
    
    }
  }
  for (j of arr2){
    if (!arr1.includes(j)){
      newArr.push(j)
    }
  }
  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:

If you look at the error it will say:
“Can’t find variable: i”

You have not declared your variables i and j.

I haven’t used

But a quick look says there is other background code added. I don’t think they would fix undeclared variables, but maybe the variables were already declared in some boilerplate code.

I’m not sure what you mean by your code works in Chrome

Chrome is a web browser, and I suspect you are using Chrome to access freeCodeCamp?

Hi,

thank you for your comment. I mean that the code works with the Chrome console.

By the way, I can pass the test, putting “let” in the for…of loop, maybe FCC works in a strict mode.

Yes you have to use let or var or const to declare your variable. Perhaps in the other places you were writing code it was declared outside your function. But either way it still needs to be declared.

Quoted from the docs above:

SyntaxSection

variable

On each iteration a value of a different property is assigned to variable . variable may be declared with const , let , or var .