Object.hasOwnintermediate// Check if a property is directly on the object
const obj = { name: 'Alice' }
Object.hasOwn(obj, 'name') // β true
Object.hasOwn(obj, 'toString') // β falseUse Object.hasOwn() to reliably check if a property is an own property, without being fooled by inherited properties.
The in operator finds inherited properties, but Object.hasOwn does not β it is strictly limited to own properties.
Challenge: Implement ownVsInherited(proto, obj, key) that returns an object with ownResult (from Object.hasOwn) and inResult (from key in obj).
const proto = { x: 1 }
const obj = Object.create(proto)
ownVsInherited(proto, obj, 'x')
// β { ownResult: false, inResult: true }