Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Function

Object.hasOwn

Object.hasOwn() returns whether an object contains a specified property as its own property. It excludes inherited properties and works with null-prototype objects.

Since
2022

How it works

Call Object.hasOwn with an object and a property key. It converts the inputs as needed and reports whether that key is defined directly on the object, without searching its prototype chain; the key may be a string or a Symbol.

Syntax

Object.hasOwn(obj, prop)

Parameters

NameTypeDescription
objobjectThe JavaScript object instance to test.
propstring | symbolThe String name or Symbol of the property to test.

Returns

true if the specified object has directly defined the specified property; otherwise false.

Key points

  • It tests whether a property belongs directly to the supplied object.
  • Inherited and absent properties are rejected.
  • The property key can be either a string or a Symbol.
  • The result is a boolean indicating direct ownership.
  • Ownership is independent of the property's stored value.
  • Prefer this static method for null-prototype objects and objects that may override hasOwnProperty.

Common mistakes

  • Do not use it when inherited properties should count; use the in operator for that broader check.
  • A missing key and an inherited key both produce false.

Example: Check direct object properties

const record = Object.create(null);
record.status = undefined;

console.log(Object.hasOwn(record, "status")); // true
console.log(Object.hasOwn(record, "toString")); // false
console.log(Object.hasOwn({ value: null }, "value")); // true

This checks direct properties, including one whose value is undefined, while excluding inherited properties and working with a null-prototype object.

When to use it

Check field presence

Validate that an input record explicitly contains a field, even when its value is undefined or null.

Handle null-prototype objects

Safely inspect dictionaries created with Object.create(null).

Exclude inherited properties

Filter enumerable or prototype-chain traversals to direct properties only.

Test symbol properties

Check keys that are represented by Symbols rather than strings.

  • Object.prototype.hasOwnProperty()
  • in operator
  • Object.getOwnPropertyNames()
  • Object.keys()

Source: Object.hasOwn() - JavaScript | MDN. Checked 2026-10-15.