0

I am confused why the following does not evaluate to true. How do I compare whether two objects are the same?

var x = new Object();
var y = {};
x == y // false

function Person(name) {
  this.name = name;
}

var p1 = new Person("Chris");
var p2 = new Person("Chris");
p1 == p2 // false
Maximus S
  • 10,759
  • 19
  • 75
  • 154

1 Answers1

2

Without going into how a JS engine works you can understand it by just thinking of it like objects are in the real world. If x is a ball and y is a chair, they aren't equal just because they are both objects. And if you know two people named Chris they aren't the same person they just have the same name.

Joseph Dailey
  • 4,735
  • 2
  • 15
  • 18