JS Built-ins
ObjectObject.createintermediate

Object.create() β€” verify with getPrototypeOf

πŸ“– Usage Example
// 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.

Object.create() β€” confirming the prototype

Object.getPrototypeOf(obj) returns the prototype set by Object.create, allowing you to confirm the prototype chain.

Challenge: Implement protoMatches(proto, obj) that returns whether Object.getPrototypeOf(obj) is strictly equal to proto.

const p = {}
const o = Object.create(p)
protoMatches(p, o) // β†’ true
πŸ’‘ Hints (2)
  • β€’ `Object.getPrototypeOf(obj)` is the standard way to inspect the prototype.
  • β€’ Use `===` for reference equality, not `==` or `toEqual`.