JavaScript Quiz: 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.

मीडियम 10 सवाल ~6 मिनट पास होने के लिए 80% Node.js 22

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 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());
जवाब दिखाएं

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.

इस क्विज़ में क्या है

  • 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

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।