When you use ===
on two object references (names) such as Rectangle.prototype
and Shape.prototype
, you are testing whether both references actually refer to the very same object. If you have two distinct objects that happen to contain the same values inside them, or two distinct objects where one is the prototype of the other, they will not compare equal.
Your call to Object.create()
creates a new object. It will never compare equal to any other object. Rectangle.prototype
is a brand new object you've just created. It's not a reference to the same object as Shape.prototype
. The prototype of Rectangle.prototype
is Shape.prototype
, but that doesn't make them the same object. So they will compare unequal.
By way of contrast, suppose you had done this:
Rectangle.prototype = Shape.prototype;
Now Rectangle.prototype
and Shape.prototype
are both references to the same object, because that's what the =
operator does. Unlike Object.create()
, the =
operator doesn't create a new object, only a new reference to the same object. If you then use ===
to compare them, they will compare equal, because the two names literally refer to the very same object.