Check if a property exists:
let user = { name: "Alice", age: 30 }
// Using 'in' operator
console.log("name" in user) // true
console.log("email" in user) // false
// Using hasOwnProperty
console.log(user.hasOwnProperty("name")) // true
console.log(user.hasOwnProperty("email")) // false
in checks inherited properties too. hasOwnProperty checks only the object's own properties.