What is the prototype chain and how does the class syntax relate to it?
Suggested answer
JavaScript uses prototypal inheritance. Every object has an internal [[Prototype]] link to another object. When a property is accessed, JS traverses the prototype chain until found or reaches null. Object.getPrototypeOf(obj) returns the prototype. Functions have a prototype property — objects created with new Fn() have Fn.prototype as their prototype. Class syntax is syntactic sugar over the prototype chain — it does not introduce a new inheritance model. class Animal { speak() {...} } class Dog extends Animal { speak() { super.speak(); } } — Dog.prototype inherits from Animal.prototype. extends sets up the prototype chain. super() must be called in a subclass constructor before accessing this. In LWC, all components extend LightningElement which provides the component lifecycle APIs.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.