Problem Statement
How do hasOwnProperty and the in operator differ?
Explanation
obj.hasOwnProperty('x') is true only if x is an own property.
'x' in obj returns true if x exists on the object or anywhere in its prototype chain.
Code Solution
SolutionRead Only
const proto = { a: 1 };
const o = Object.create(proto);
o.b = 2;
console.log(o.hasOwnProperty('a')); // false
console.log('a' in o); // true