Problem Statement
Explain prototypal inheritance in JavaScript with a simple example.
Explanation
In JavaScript, objects inherit directly from other objects.
Every object has an internal [[Prototype]] pointing to another object (or null). When a property is missing, the engine looks up the chain.
This model enables sharing behavior without copying methods to each instance.
Code Solution
SolutionRead Only
const animal = { speak(){ return '...'; } };
const dog = Object.create(animal);
dog.speak = function(){ return 'woof'; };
const beagle = Object.create(dog);
console.log(beagle.speak()); // 'woof' (found on dog, not animal)