What is the output of the following? “`js class Animal { constructor(name) { this.name = name; } speak() { return `${this.name} makes a noise.`; } } class Dog extends Animal { speak() { return `${this.name} barks.`; } } const d = new Dog(‘Rex’); console.log(d.speak()); console.log(d instanceof Animal); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js class Animal { constructor(name) { this.name = name; } speak() { return `${this.name} makes a noise.`; } } class Dog extends Animal { speak() { return `${this.name} barks.`; } } const d = new Dog(‘Rex’); console.log(d.speak()); console.log(d instanceof Animal); “`

Key points

  • Method overriding in JavaScript classes
  • Proper usage of the `instanceof` operator
  • Understanding inheritance in JavaScript

Ready to go further?

Related questions