Difference Between in and hasOwnProperty in JavaScript Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In JavaScript, working with the objects often involves checking for the presence of properties. The two commonly used methods for this purpose are in and hasOwnProperty. Both serve to check for the properties in objects but they have key differences in how they operate and their intended use cases.These are the following topics that we are going to discuss in this article:Table of ContentWhat is in?What is hasOwnProperty?Difference Between in and hasOwnProperty What is in?The in operator checks whether a specified property exists in an object or its prototype chain. It returns true if the property is found either directly on the object or in its prototype chain and false otherwise.CharacteristicsPrototype Chain: The in checks not only the object's own properties but also properties in its prototype chain.Boolean Return: The Returns a Boolean value indicating the presence of the property.Non-method: It is an operator, not a method, so it does not require parentheses.ApplicationsPrototype Inheritance: Useful when we need to check for the properties that might be inherited from the prototype.General Existence Check: The Suitable for the general checks where prototype properties are also relevant.Example: This example shows the use of in operator. JavaScript let person = { name: "kumar" }; console.log("name" in person); console.log("toString" in person); console.log("age" in person); Outputtrue true false What is hasOwnProperty?The hasOwnProperty method checks whether a specified the property exists directly on an object and not on its prototype chain. It returns true if the property is found directly on the object and false otherwise.CharacteristicsDirect Properties Only: Checks only the object's own properties ignoring the prototype chain.Method Call: It is a method and needs to be called on the object with the parentheses.Boolean Return: The Returns a boolean value indicating the presence of the property.ApplicationsObject Specific Checks: Ideal for verifying if a property is an object's own property and not inherited.Safeguard Against Prototypes: Useful in scenarios where prototype properties should not be considered.Example: This example shows the use of hasOwnProperty method. JavaScript let person = { name: "kumar" }; console.log(person.hasOwnProperty("name")); console.log(person.hasOwnProperty("toString")); console.log(person.hasOwnProperty("age")); Outputtrue false false Difference Between in and hasOwnPropertyCharacteristicsin hasOwnPropertyPrototype Chain The Checks properties in the object and its prototypes The Checks only own propertiesTypeOperatorMethodSyntax"property" in object object.hasOwnProperty("property")Return Type BooleanBooleanUse Case The General property existence check including the inheritance Check for the properties directly on the objectConclusionThe in operator and hasOwnProperty method are both essential tools for the property checking in JavaScript. Understanding their differences is crucial for their correct application especially in scenarios involving the prototype inheritance. While in is useful for broader checks including the prototypes hasOwnProperty provides a more focused approach by only considering an object's own properties. Comment More infoAdvertise with us Next Article Differences Between for-in and for-of Statement in JavaScript S subramanyasmgm Follow Improve Article Tags : JavaScript Web Technologies Similar Reads Difference Between for...in and Object.keys() in JavaScript The for...in and Object.keys() in JavaScript are used to iterate over the properties of an object. While they might seem similar at first glance they have distinct usage, behavior, and characteristics. This article will explore these differences in detail.These are the following topics that we are g 3 min read Differences Between for-in and for-of Statement in JavaScript The for..in loop is designed for iterating over an object's keys or property names, making it useful when accessing each property in an object. Although it can also be used to iterate over the indices of an array. Conversely, the for..of loop is intended to iterate directly over values in iterable c 2 min read Difference Between Object.keys() and Object.getOwnPropertyNames() in JavaScript In JavaScript, Object.keys() and Object.getOwnPropertyNames() both retrieve properties of an object but differ in scope. Object.keys() returns an array of an object's own enumerable property names. In contrast, Object.getOwnPropertyNames() returns an array of all own property names, including non-en 2 min read What is the difference between freeze and seal in JavaScript? In JavaScript, Object.freeze makes an object immutable, preventing any changes to existing properties and values. Object.seal allows changes to existing properties but prevents adding or removing properties. Both methods enforce strict immutability, but freeze is stricter than seal. Table of Content 2 min read Difference between native, host and user objects JavaScript objects are broadly classified into the following categories: native javascript objects, user objects, and host javascript objects. Native objects: Native javascript objects are standard javascript objects which are provided by javascript itself. They are also known as built-in objects, p 3 min read Difference between Object.keys() and Object.entries() methods in JavaScript Object.keys() and Object.entries() are methods in JavaScript used to iterate over the properties of an object. They differ in how they provide access to object properties: Object.keys() returns an array of a given object's own enumerable property names, while Object.entries() returns an array of a g 2 min read Like