JS: Object.prototype.hasOwnProperty

By Xah Lee. Date: . Last updated: .
Return true if object obj has own property key key (string or Symbol). Else, false.
const xx = { "p": 1 };
console.log(xx.hasOwnProperty("y") === false);

Example with a Symbol key.

// check if a object has own property of a symbol key
const ss = Symbol();
const jj = {};
jj[ss] = 3;
// Object.prototype.hasOwnProperty return false if the property is not own property

const xx = { "p": 1 };

// create a object yy, with parent xx
const yy = Object.create(xx);

console.log(yy.hasOwnProperty("p") === false);

[see Access Property]

JavaScript, Check Property Existence

BUY ΣJS JavaScript in Depth