MediumPrototypes & Inheritance💻 Output Question

Class method override and instanceof

💡

Hint

Subclass instances are instanceof both the subclass and all parent classes.

What does this output?

class Animal {
  speak() { return 'generic'; }
}
class Dog extends Animal {
  speak() { return 'woof'; }
}
const d = new Dog();
console.log(d.speak());
console.log(d instanceof Dog);
console.log(d instanceof Animal);

Correct Output

woof
true
true

Why this output?

Explanation: Dog.speak() overrides Animal.speak(). d is instanceof both since Dog extends Animal.

Key Insight: Subclass instances are instanceof both the subclass and all parent classes.

More Prototypes & Inheritance Output Questions

Easyinstanceof traverses the prototype chainMediumhasOwnProperty vs in operatorMediumsuper calls the parent methodMediumObject.create sets prototype directly

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz