# JavaScript's Prototypal Inheritance

1 min read

Prototypal inheritance is a feature in JavaScript that allows objects to inherit properties and methods from other objects. Here’s an example:

const parent = {
greet() {
console.log('Hello from parent!')
},
}
const child = Object.create(parent)
child.greet() // Hello from parent!

Prototypal inheritance is a flexible way to share behavior between objects without using classes.

Testing Prototypal Inheritance
node -e "const parent = { greet() { console.log('Hello from parent!'); } }; const child = Object.create(parent); child.greet();"

Comments