JavaScriptQuestion 22 of 36
What is inheritance?
Answer out loud or in your head first, then compare.
Answer
It lets one type reuse the behaviour of another.
JavaScript
class Animal {
speak() {
console.log("sound");
}
}
class Dog extends Animal {
bark() {
console.log("woof");
}
}Dog has:
JavaScript
dog.speak();
dog.bark();Under the hood this works through the prototype chain.
How did it go? Be honest — “Not yet” puts the question on your review list.