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.
Object.prototype.hasOwnProperty can fail if the object has a property named hasOwnProperty or has no prototype. Object.hasOwn is always safe.
Challenge: Implement safeCheck(obj, key) that uses Object.hasOwn (not hasOwnProperty) to check ownership.
safeCheck({ a: 1 }, 'a') // β true