Object.createintermediate// Create an object with a specific prototype
const proto = { greet() { return 'hi' } }
const child = Object.create(proto)
child.greet() // β 'hi'Use Object.create() to create a new object with a specific prototype, enabling prototype-based inheritance.
Objects created with Object.create(proto) can access methods defined on the prototype through the prototype chain.
Challenge: Implement makeGreeter(name) that creates an object with name as an own property, using { greet() { return 'Hello, ' + this.name } } as its prototype.
makeGreeter('Alice').greet() // β 'Hello, Alice'