0

JavaScript is showing UNDEFINED along with OUTPUT while trying to call an INHERITANCE method, Anyone knows why that is?

This is the code:

class Car {
  drive() {
    console.log(`I am driving ${this.model}`)
  }
}

class Polo extends Car {
  model = "Polo GTI"
  color = "red"
}

let polo = new Polo()

console.log(polo.drive())

Output:

I am driving Polo GTI
undefined
Barmar
  • 741,623
  • 53
  • 500
  • 612
Nazeef
  • 11
  • 2

0 Answers0