A penguin is an animal and an emperor penguin is a penguin. Are emperor penguins animals too? Of course!
The "prototype chain" in JavaScript. knows this as well. If JavaScript. encounters something it can't find in the current class's methods or properties, it looks up the prototype chain to see if it's defined in a class that it inherits from. This keeps going upwards until it stops all the way at the top: the mighty Object.prototype
(more on this later). By default, all classes inherit directly from Object
, unless we change the class's prototype
, like we've been doing for Penguin
and Emperor
.