JavaScript hasOwnProperty() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

obj.hasOwnProperty(prop) returns true when prop is an own property of obj. Inherited properties return false.

Objects made with Object.create(null) have no hasOwnProperty method. Prefer Object.hasOwn(obj, prop) in modern code, or call Object.prototype.hasOwnProperty.call(obj, prop).

Syntax

Call obj.hasOwnProperty() like this. Start with this line.

JavaScript
obj.hasOwnProperty(prop)
CallWhat it does
obj.hasOwnProperty("name")True if name is an own property.
Object.hasOwn(obj, "name")Modern static alternative; safer for null-prototype objects.
Object.prototype.hasOwnProperty.call(obj, "name")Safe call when obj might not inherit from Object.prototype.

Call on the object. prop is usually a string key (Symbols also work).

Library declarations
JavaScript
obj.hasOwnProperty(prop)
JavaScript
object.hasOwnProperty(v: PropertyKey): boolean

Parameters

ParameterDescription
propRequired. The property name (string) or Symbol to test.

Return Value

Return ValueDescription
booleantrue if the property is own; otherwise false.

JavaScript Examples

Own Property vs Inherited Property

Compare hasOwnProperty with the in operator.

JavaScript
var proto = { role: "guest" };
var user = Object.create(proto);
user.name = "Ada";

console.log(user.hasOwnProperty("name"));
console.log(user.hasOwnProperty("role"));
console.log("role" in user);
Try It Yourself

How It Works

  1. Own key. name lives on user, so hasOwnProperty is true.
  2. Inherited key. role comes from the prototype, so hasOwnProperty is false.
  3. in sees both. "role" in user is still true because inheritance counts for in.

Object.create(null) Needs a Safe Call

A null-prototype object has no hasOwnProperty. Use Object.hasOwn or .call.

JavaScript
var dict = Object.create(null);
dict.apple = 1;

console.log(typeof dict.hasOwnProperty);
console.log(Object.hasOwn(dict, "apple"));
console.log(Object.prototype.hasOwnProperty.call(dict, "apple"));
Try It Yourself

How It Works

  1. Method missing. dict.hasOwnProperty is undefined.
  2. Object.hasOwn. The static helper works on null-prototype objects.
  3. Prototype call. Borrowing the method with .call also works.

When the Object Has Its Own hasOwnProperty Key

If a data property replaces the method, call through Object.prototype.

JavaScript
var weird = {
  hasOwnProperty: "nope",
  color: "red"
};

console.log(typeof weird.hasOwnProperty);
console.log(Object.prototype.hasOwnProperty.call(weird, "color"));
console.log(Object.hasOwn(weird, "color"));
Try It Yourself

How It Works

  1. Method overwritten. Here hasOwnProperty is a string, not a function.
  2. Borrow safely. Calling the real method via Object.prototype still works.
  3. Modern helper. Object.hasOwn avoids this trap entirely.

Browser & Runtime Support

hasOwnProperty() has been part of JavaScript since the earliest versions (ES1) and is Baseline everywhere.

✓ ES1 · Baseline

obj.hasOwnProperty()

Works in every browser and runtime. For new code, Object.hasOwn is often clearer and safer.

100% 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.prototype.hasOwnProperty Excellent

Bottom line: Universally available. Prefer Object.hasOwn(obj, prop) when you support modern engines.

Frequently Asked Questions

It returns true only for own properties. Inherited properties return false.
in returns true for own and inherited enumerable/non-enumerable keys on the chain. hasOwnProperty ignores inheritance.
Those objects do not inherit from Object.prototype, so the method is missing. Use Object.hasOwn or Object.prototype.hasOwnProperty.call.
Yes in modern JavaScript. It is clearer and avoids null-prototype and shadowing issues.
Yes. Pass the Symbol as the argument and it will report own Symbol properties correctly.

Next: isPrototypeOf()

Check if one object sits in another’s prototype chain.

isPrototypeOf() 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