0

I am trying to understand why this simple code is saying false instead of true.

let test1 = JSON.parse("[]");
let test2 = JSON.parse("[]");

console.log(test1 == test2);

Surely this code should be true but I always get it saying false. Whats the issue?

Thanks

  • 1
    It is working perfectly, `[] === []` and `[] == []` are false. https://stackoverflow.com/questions/13703222/why-is-false-in-javascript – Robbie Milejczak Feb 18 '20 at 14:10
  • Objects are equal by reference, [] is a new object with a new reference, the right hand [] is also a brand new object with a new reference, so they are not equal.. – Maniraj Murugan Feb 18 '20 at 14:12

0 Answers0