VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-object-hasown-method/

⇱ JavaScript Object hasOwn() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Object hasOwn() Method

Last Updated : 23 Jul, 2025

JavaScripthasOwn() method is used to check if the object has the specified property or not. It returns true if the property exists else false. This method was introduced as a replacement for the Object.hasOwnProperty() method. It is different from in operator as it does not check for inherited properties.

Syntax:

Object.hasOwn(obj, prop)

Parameters:

This method takes two parameters

  • obj: This is the JavaScript object on which the check is to be applied
  • prop: It is the property on which the check is to be applied

Return Value:

  • A boolean value true if exists else false.

Example 1: This example uses the hasOwn() method to check if a property exists or not

Output:

true
true
false

Example 2: This example will compare the in operator and Object.hasOwn() method.

Output: The in operator returns true for even inherited properties like toString is an inherited method for all JavaScript objeccts.

true
true
false
true

Example 3: This method compares the hasOwnProperty() method and hasOwn() method.

Output: The hasOwnProperty() method does not work on null objects but hasOwn() method works. So it is better than hasOwnProperty() method

👁 Image

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari
Comment
Article Tags: