Released June 25, 2021 · Tagged ECMAScript

Recommend the use of the Object. HasOwn () method, because it makes Object. The prototype. The hasOwnProperty () is more easy to use.


The proposal is currently in its third stage

Why does the Object. Hasown proposal appear?

These days, code like this is common:

const hasOwnProperty = Object.prototype.hasOwnProperty;

if (, 'foo')) {
  // `object` has property `foo`.

Or some library makes use of Object. The prototype. HasOwnProperty is simpler: NPM: from the NPM: lodash. From the See Related

Using the new Object.hasOwn function, we can abbreviate the above code to:

if (Object.hasOwn(object, 'foo')) {
  // `object` has property `foo`.

In everyday development, there are some common uses where methods on Object.Prototype may sometimes be unavailable or redefined.

Such as:

1. Object. The create (null) :

Object.create(null) creates an Object that does not inherit from Object.prototype, making methods on Object.prototype inaccessible.

Object.create(null).hasOwnProperty("foo") // Uncaught TypeError: Object.create(...) .hasOwnProperty is not a function

2. Redefine hasOwnProperty:

If you override the object’s built-in properties, then when you call a property (e.g.,.hasOwnProperty), you will not be calling the object’s built-in properties

let object = { hasOwnProperty() { throw new Error("gotcha!" ) } } object.hasOwnProperty("foo") // Uncaught Error: gotcha!

3. ESLint no-prototype-builtins

In ESLint’s Built in Rule, it is forbidden to use Object.prototypes of built-in functions directly

No-prototype-builtins Note in the ESLint documentation:

Examples of errors with this rule:

/*eslint no-prototype-builtins: "error"*/ var hasBarProperty = foo.hasOwnProperty("bar"); .

A correct example of this rule:

/*eslint no-prototype-builtins: "error"*/ var hasBarProperty =, "bar"); .

The proposal

The proposal adds an Object.hasOwn(Object, property) method that behaves the same as calling hasOwnProperty. Call (Object, property)

let object = { foo: false }
Object.hasOwn(object, "foo") // true

let object2 = Object.create({ foo: true })
Object.hasOwn(object2, "foo") // false

let object3 = Object.create(null)
Object.hasOwn(object3, "foo") // false

Why not use object.hasOwnProperty (Object, property)?

Object.hasOwnProperty(Property) already exists today, and since Object itself inherits from Object.Prototype, defining a new method with a different name would be a noticeable change.

Why is it called hasOwn?

See Issue #3

Object.hasown is already available in V8 v9.3 and can be implemented with the –harmony-object-has-own flag, and will be available in Chrome shortly.


  • Accessible Object.prototype.hasOwnProperty()