JavaScript Object.hasOwn() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

Object.hasOwn(obj, prop) returns true when prop is an own property of obj. Inherited properties from the prototype chain return false.

Prefer Object.hasOwn over obj.hasOwnProperty(prop). It is a static call, works on objects made with Object.create(null), and cannot be broken by a shadowed hasOwnProperty method.

Syntax

Call Object.hasOwn() like this. Start with this line.

JavaScript
Object.hasOwn(obj, prop)
CallWhat it does
Object.hasOwn(obj, prop)Returns true if prop is an own property of obj.

Built into JavaScript. Call on Object — no import required.

Library declarations
JavaScript
Object.hasOwn(obj, prop)
JavaScript
hasOwn(o: object, v: PropertyKey): boolean;

Parameters

ParameterDescription
objRequired. The object to test. Must be an object (not null or undefined).
propRequired. The property key to look for (string or symbol).

Return Value

Return ValueDescription
booleantrue if the property exists directly on the object; false if it is missing or only inherited.

JavaScript Examples

Example 1 — Basic Use

Check own properties on a simple object.

JavaScript
var user = { name: "Ada", age: 36 };

console.log(Object.hasOwn(user, "name"));
console.log(Object.hasOwn(user, "email"));
console.log(Object.hasOwn(user, "toString"));
Try It Yourself

How It Works

  1. Own key name is defined on user, so the result is true.
  2. Missing key email was never set, so the result is false.
  3. Inherited method toString comes from Object.prototype, so hasOwn returns false.

Example 2 — Object.create(null)

Objects without a prototype still work with Object.hasOwn.

JavaScript
var dict = Object.create(null);
dict.color = "blue";

console.log(Object.hasOwn(dict, "color"));
console.log(typeof dict.hasOwnProperty);
console.log(Object.hasOwn(dict, "toString"));
Try It Yourself

How It Works

  1. No prototype methods Object.create(null) objects do not inherit hasOwnProperty.
  2. Static call still works Object.hasOwn(dict, "color") correctly finds the own property.
  3. Why prefer hasOwn Calling dict.hasOwnProperty(...) would throw because that method does not exist on dict.

Example 3 — Value undefined

A property set to undefined still counts as present.

JavaScript
var box = { empty: undefined };

console.log(box.empty);
console.log(Object.hasOwn(box, "empty"));
console.log(Object.hasOwn(box, "missing"));
console.log("empty" in box);
Try It Yourself

How It Works

  1. Value vs existence Reading box.empty gives undefined, but the key still exists.
  2. hasOwn sees it Object.hasOwn(box, "empty") is true because the property is own.
  3. Missing is different missing was never defined, so hasOwn is false. The in operator also finds own keys (and inherited ones).

Browser & Runtime Support

Object.hasOwn() was added in ES2022. It is Baseline in current browsers; older engines can fall back to Object.prototype.hasOwnProperty.call.

✓ Baseline · ES2022

Object.hasOwn()

Supported in Chrome 93+, Firefox 92+, Safari 15.4+, Edge 93+, and Node.js 16.9+.

95% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Object.hasOwn Excellent

Bottom line: Prefer Object.hasOwn in new code. For very old environments, use Object.prototype.hasOwnProperty.call(obj, key).

Frequently Asked Questions

It returns true if the object has an own property with that key, and false if the key is missing or only inherited from the prototype chain.
Object.hasOwn is a static method, works on Object.create(null) objects, and is not affected if the object defines its own hasOwnProperty property.
No. Inherited properties return false. Use the in operator if you want to include the prototype chain.
Yes. If the key exists on the object, hasOwn returns true even when the value is undefined.
Yes. Pass the Symbol as the second argument: Object.hasOwn(obj, mySymbol).

Next: is()

Compare two values with SameValue rules (NaN and ±0).

is() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful