Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.prototype.hasOwnProperty() — checking own properties

Object.prototype.hasOwnProperty() checks whether a property belongs directly to an object rather than its prototype. Learn how it differs from in and how to call it safely when the method is shadowed.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

obj.hasOwnProperty(prop)
Object.prototype.hasOwnProperty.call(obj, prop)

Object.prototype.hasOwnProperty returns true when the object has the specified own property, and false when the property is inherited or absent. The prop argument can be a string name or a symbol. A value of null or undefined does not mean the property is absent.

The method includes both enumerable and non-enumerable properties. The in operator also checks the prototype chain, so it can return true where hasOwnProperty() returns false.

Calling obj.hasOwnProperty(prop) is unreliable if the object shadows that method, and an object created with Object.create(null) does not inherit it at all. Use Object.prototype.hasOwnProperty.call(obj, prop) to avoid both problems. In new code, prefer Object.hasOwn(obj, prop) when the target environment supports it.

Examples

const obj = Object.create({ inherited: 1 });
obj.own = undefined;
obj.hasOwnProperty = false;

console.log(Object.prototype.hasOwnProperty.call(obj, "own"));
console.log(Object.prototype.hasOwnProperty.call(obj, "inherited"));
console.log("inherited" in obj);
console.log(Object.prototype.hasOwnProperty.call(obj, "missing"));

Result

true
false
true
false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources