JavaScript (ES2026) reference · Object Methods

JavaScript Object.hasOwn() Method

Return true if an object has a property of its own (not inherited). The safer replacement for hasOwnProperty().

JavaScript (ES2026) Since ES2022

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.hasOwn(obj, prop)

Parameters

ParameterDescription
obj The object to inspect or change.
prop The property name.

Return value

true or false.

Examples

Own vs inheritedTry it yourself
const user = { name: "Ada" };
console.log(Object.hasOwn(user, "name"), Object.hasOwn(user, "toString"), "toString" in user);

Output

true false true
Works on null-prototype objectsTry it yourself
const dict = Object.create(null);
dict.key = 1;
console.log(Object.hasOwn(dict, "key"));
// dict.hasOwnProperty("key") would throw: there is no prototype

Output

true

Version history

VersionChange
JavaScript ES2022Added

In other languages

Was this page helpful?