Quiz di JavaScript: Classes & Inheritance

This JavaScript quiz covers the class syntax used in most modern code. You will predict output for subclasses, super calls, overridden methods and class fields, and spot the classic errors with this.

Medio 10 domande ~6 minuti Superato con il 80% Node.js 22

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 10

What does this print?

class Animal {
  constructor(name) { this.name = name; }
  speak() { return `${this.name} makes a sound`; }
}
class Dog extends Animal {
  speak() { return `${super.speak()}, woof`; }
}
console.log(new Dog("Rex").speak());
Mostra la risposta

A. Rex makes a sound, woof Dog has no constructor, so the default one passes "Rex" to Animal's constructor. super.speak() calls the parent method with the same this, then Dog appends its own text.

Cosa copre questo quiz

  • Constructors, methods and class fields
  • extends and calling super() and super.method()
  • Method overriding and dynamic this
  • Losing this when a method is passed around
  • Private #fields

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.