---
title: "prefer-object-has-own"
description: "Require `Object.hasOwn()` instead of `Object.prototype.hasOwnProperty.call()`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "eslint"
aliases: ["eslint/prefer-object-has-own"]
kind: "suggestion"
category: "style"
default: "off"
fixable: "yes"
typeAware: false
deprecated: false
---

`Object.prototype.hasOwnProperty.call(user, key)` is the long way to ask if a property belongs to the object itself. It's written like that so it also works on objects without a prototype. `Object.hasOwn(user, key)` does the same thing and says what it means.

The shorter spellings `Object.hasOwnProperty.call()` and `{}.hasOwnProperty.call()` are reported too.

`--fix` replaces everything before the arguments with `Object.hasOwn`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"prefer-object-has-own" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
if (Object.prototype.hasOwnProperty.call(user, "email")) {
  send(user.email);
}

const isSet = {}.hasOwnProperty.call(settings, key);
const isCached = Object.hasOwnProperty.call(cache, id);
```

Not reported:

{/* good */}
```js
if (Object.hasOwn(user, "email")) {
  send(user.email);
}

const isSet = Object.hasOwn(settings, key);
const isCached = Object.hasOwn(cache, id);
```

## When not to use it

`Object.hasOwn` is part of ES2022. Turn the rule off if your code runs on an older engine without a polyfill.
