On this page
  1. Object.hasOwnProperty
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Object.hasOwnProperty

Prev: defineProperty | Up: Object | Next: Array
Rel: Object.hasOwn(), Object, Object & Reflect Guide
Ref: MDN Web Docs — Object.hasOwnProperty
Tags: #public #web #javascript #builtins #object #tier/legacy


Signature & Overview

obj.hasOwnProperty(prop)

Prototype method checking own property existence; breaks on Object.create(null) or shadowed property names.

Legacy / Avoid: Prefer Object.hasOwn() in all new code.

Notes & Pitfalls

Example

const obj = { a: 1 };
console.assert(Object.prototype.hasOwnProperty.call(obj, "a") === true);
console.assert(Object.hasOwn(obj, "a") === true);

Linked from

Related notes