The difference is pretty simple. Check out MDN's documentation of instanceOf. If you have an instance Fido
that is an instance of GreatDane
which is an instance of Dog
which is an instance of Object
, the following will be the case:
Fido instanceof GreatDane // true
Fido instanceof Dog // true
Fido instanceof Object // true
Fido.constructor === GreatDane // true
However, the following will not be true:
Fido.constructor === Dog // false
Fido.constructor === Object // false
So you can see the instanceOf
keyword travels up the lineage, where constructor
is looking at the actual function that created your instance.
Neither is better. It depends on your situation. What do you want to know about each object?
As Patrick Roberts points out in the comment below, Fido.constructor
would be the actual constructor function inherited from GreatDane
. And you are able to modify it, so if you ever changed the constructor, your comparison would then return false
.