Inheritance with extends — JS Technical Interview Questions & Answers
Sharing behaviour between related classes.
Inheritance with extends
- Inheritance with extends (js) is a JS topic. In plain words you use it for a short Inheritance with extends js example in a script in the browser. Don’t start with a slogan — start with that picture.
- Smallest example: the smallest Inheritance with extends js example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Inheritance with extends (js).
- From the example next to this theory: Sharing behaviour between related classes.
- Trap: only saying “Inheritance with extends js” with no example. Fix that before you talk about advanced JS.
- Viva: what is Inheritance with extends (js)? Then show the smallest Inheritance with extends js example you can type. Then name the trap.
Technical Interview Tip: What is Inheritance with extends (js)? Show this: the smallest Inheritance with extends js example you can type. Trap: only saying “Inheritance with extends js” with no example.
Code Examples for Inheritance with extends
Inheritance with extends — working example
class Person {
constructor(name) {
this.name = name;
}
greet() {
return "Hi " + this.name;
}
}
class Student extends Person {
constructor(name, track) {
super(name);
this.track = track;
}
}
const s = new Student("Ada", "JS");
console.log(s.greet(), s.track);
console.log(Object.getPrototypeOf(s) === Student.prototype);Inheritance with extends — eS classes are sugar over prototypes; extends sets up the prototype chain; super calls the parent.
How to Explain Inheritance with extends to an Interviewer
What is Inheritance with extends (js)?
Used for a short Inheritance with extends js example a script in the browser Not just the heading
Give one small example of Inheritance with extends (js).
the smallest Inheritance with extends js example you can type Sharing behaviour between related classes
What mistake do beginners make with Inheritance with extends (js)?
only saying “Inheritance with extends js” with no example Show the fix
Where do you use Inheritance with extends (js)?
a script in the browser a short Inheritance with extends js example