Update appNew update is available. Click here to update.
Last Updated: Sep 21, 2023

JavaScript hasOwnProperty() Method


Javascript is one of the significant components of web technology. It is a scripting language. It has various methods and properties that make it easy for developers to develop a website. If you want to revise Javascript concepts, check out this page. In this article, we will discuss one of its essential methods; the javascript hasOwnProperty

JavaScript hasOwnProperty() Method

What is the hasOwnProperty method?

The javascript hasOwnProperty() method helps check if the property belongs to the same object or not. The javascript hasOwnProperty() method has a boolean return type. It returns true if the property belongs to the object. If the property does not belong to the object, it returns false. 

hasOwnProperty() syntax

The hasOwnProperty() method is a built-in method of the JavaScript object. It has the following syntax:


Here, the object is the name of the object you want to check. Its property is the name of the property you want to check if it is its own property or inherited. The method returns a boolean value, true if the object has its own property, otherwise false.

hasOwnProperty() Parameters

The hasOwnProperty() method in JavaScript takes one parameter which is the property that we are testing the object for. The method is called on an object. It checks if a given property belongs only to the object itself and is not inherited from its prototype chain.

hasOwnProperty() Return Value

The hasOwnProperty() method is used in JavaScript to check if an object has a property that belongs only to itself and is not inherited from its prototype chain. It returns a boolean value of true if the object has the specified property and false if not.

Let us see how we use the javascript hasOwnProperty method through an example:

Example of Javascript hasOwnProperty()

<!DOCTYPE html>
            "Demonstration of hasOwnProperty in Javascript."
            var coding_ninjas = {  
                name: 'Coding Ninjas Studio',  
                vertical: 'resource',  
            var intern = {  
                name: 'XYZ',  



The output contains four lines. ‘coding_ninjas’ object has ‘name’ and ‘vertical’ properties, so the two lines return true as output. 

'intern' has only one property, 'name', for which the result is true‘role’ is not the property of the ‘intern’ object, so the fourth line of output contains false. 

The javascript hasOwnProperty method does not work on Inherited Properties. Inherited properties are the ones that the object inherits from the prototype object. The method returns true only on non-inherited properties.

Supported Browsers

Below is the browser lists that support the hasOwnProperty() method in Javascript.

  • Chrome (1 and above)
  • Edge (12 and above)
  • Opera (5 and above)
  • Safari (3 and above)
  • Firefox (1 and above)

Frequently Asked Questions

What does hasOwnProperty do in JavaScript?

In JavaScript, hasOwnProperty checks if an object directly possesses a specific property, ignoring inherited properties. It returns true if the property exists in the object, false if not.

What is hasOwnProperty like in JavaScript?

In JavaScript, hasOwnProperty is like a detective tool. It checks if an object actually has a specific property, excluding properties inherited from its parent objects. It returns true or false.

What is the difference between has and hasOwnProperty in JavaScript? 

In JavaScript, "has" is used to check if an object has a specific property, even if it's inherited from its prototype chain. "hasOwnProperty" is used to check if an object has its own property, which is not inherited from a parent object.

What is own property in JavaScript?

Javascript's own properties are the properties that are defined directly on the object and are not inherited from the prototype object. We can access these properties using the Object.getOwnPropertyNames() method in Javascript.

How to check if an object has properties in JavaScript?

We can check if a Javascript object has any property using the methods such as hasOwnProperty(), Object.keys(), Object.entries(), etc. We can also check for a property using the in operator in Javascript.

How to find all objects with property value in JavaScript?

To find all objects with a specific property value in JavaScript, you would typically iterate through an array of objects, checking each object's property value and collecting matching objects into a new array or performing the desired action with them.

What is the difference between hasown and in JavaScript?

In Javascript, the hasOwnProperty() is used to check for all the properties that are directly defined on the object itself. But the in operator checks for the properties both on the object and its prototype chain.

Does the hasOwnProperty work on inherited properties or values?

No, the hasOwnProperty does not work on inherited properties or values.


In this article, we learned the javascript hasOwnProperty(). We saw what the method would return on different properties of the objects. Check out more articles on javascript here

Wanna learn more about web technologies? Why not have a look at web technologies on Coding Ninjas Studio? Don’t stop yourself here. Practice data structures and algorithmsinterview questionsDBMScomputer networks, and operating systems to crack the interviews of big tech giants. Explore other fields like machine learningdeep learningcomputer vision, and big data. Also, check out Interview Experiences for different companies.

Happy learning!

Previous article
JavaScript String() Method
Next article
JavaScript Array map() method