Skip to content

Latest commit

 

History

History
29 lines (28 loc) · 453 Bytes

class-constructor.md

File metadata and controls

29 lines (28 loc) · 453 Bytes

@ katopz

What console log will print?

class Pet {
  constructor(speech) {
    this.speech = speech
  }
  static get name() {
    return 'Pet'
  }
  get name() {
    return this.constructor.name
  }
  speak() {
    return `${this.name}:${this.speech}`
  }
}
class Cat extends Pet {
  static get name() {
    return 'Cat'
  }
}

const answer = new Pet('hi') && new Cat('meow').speak()
console.log(answer)
  • "Cat:meow"
  • "Pet:hi"
  • "undefined"