Prototypes and Prototype Chain — JS Technical Interview Questions & Answers
How JS objects inherit before/under classes.
Prototypes and Prototype Chain
- Prototypes and Prototype Chain (js) is a JS topic. In plain words you use it for class Student in a tiny OOP file. Don’t start with a slogan — start with that picture.
- Smallest example: class Student { constructor(name) {} }. Type it, run it, and say what you see. If you can do that from memory, you know Prototypes and Prototype Chain (js).
- From the example next to this theory: How JS objects inherit before/under classes.
- Trap: arrow function for a method that needs this. Fix that before you talk about advanced JS.
- Viva: what is Prototypes and Prototype Chain (js)? Then show class Student { constructor(name) {} }. Then name the trap.
Technical Interview Tip: What is Prototypes and Prototype Chain (js)? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.
Code Examples for Prototypes and Prototype Chain
Prototypes and Prototype Chain — working example
class Animal {
static kingdom = "Animalia";
#secret = "private";
constructor(name) { this.name = name; }
speak() { return this.name + " speaks"; }
reveal() { return this.#secret; }
}
class Dog extends Animal {
speak() { return super.speak() + " (bark)"; }
}
const d = new Dog("Rex");
console.log(d.speak(), Animal.kingdom, d.reveal());
console.log(Object.getPrototypeOf(d) === Dog.prototype);Prototypes and Prototype Chain — oOP in JS: constructors, prototypes, inheritance, statics, and private fields (#).
How to Explain Prototypes and Prototype Chain to an Interviewer
What is Prototypes and Prototype Chain (js)?
Used for class Student a tiny OOP file Not just the heading
Give one small example of Prototypes and Prototype Chain (js).
class Student { constructor(name) {} } How JS objects inherit before/under classes
What mistake do beginners make with Prototypes and Prototype Chain (js)?
arrow function for a method that needs this Show the fix
Where do you use Prototypes and Prototype Chain (js)?
a tiny OOP file class Student