-4

So basically I assume that there is something about equal/unequal that I didn't quite understand.

enter image description here

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71

1 Answers1

1

Your problem here is not really with the == or != operators, but rather the fact that in JavaScript no two objects are the same.

var obj1 = {
  name: 'Joe'
}

var obj2 = {
  name: 'Joe'
}

var obj3 = obj1;

console.log(obj1 == obj2); // false (2 separate objects)
console.log(obj1 == obj3); // true (pointing to the same object)

var primitive1 = 'aaa';
var primitive2 = 'aaa';

console.log(primitive1 == primitive2); // true (compared by value)

When you compare those objects, JavaScript is simply comparing by reference. You have created 2 different objects in memory and JavaScript compares non-primitives by looking at the reference only.

Sébastien
  • 11,860
  • 11
  • 58
  • 78