Using Inheritance in different ways

Animal is an object that’s parent of Dog object and I’d like to know what the difference between the following two declarations while setting the prototype of the Dog object.

Dog.prototype = Object.create(Animal.prototype);

Dog.prototype = Animal.prototype;

The first sets the prototype of Dog to be an instance of Animal.

The second assigns the Animal prototype to Dog’s prototype.

You do not want to do the second because if you later want to make changes to Dog’s prototype you will also be changing Animal’s prototype.

Why? How? When you assign an object to a variable, you are not creating a copy of the object and assigning it to the variable, you are assigning a reference to the location in memory where the object data is stored.

Got it. Thanks. I guess, the lesson here is we have to be careful in the way we reference things.