To check if a key exists in a JavaScript object, we use the hasOwnProperty method.
For instance, we write
const obj = { key: undefined };
console.log(obj.hasOwnProperty("key"));
to call obj.hasOwnProperty to check if the 'key' property is in the obj object itself.