0

I let function A and function B print the same thing. But why the object constructed by A and the object b constructed by B are not equal?

function A() {
  alert("k")
};

function B() {
  alert("k")
};

let a = new A();
let b = new B();

alert(a == b);
lejlun
  • 4,140
  • 2
  • 15
  • 31
Anee go
  • 65
  • 5
  • 3
    Because `new` creates a new object. Even `let a = new A(); let b = new A();` will return distinct objects. – Raymond Chen Aug 25 '21 at 21:16
  • == works differently on different types of objects. for functions, I think it's just comparing addresses in memory. – Rick Aug 25 '21 at 21:20

0 Answers0