# property testing

* [JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md) ⟩ [property](/web/js/val/obj/prop.md) ⟩ testing properties&#x20;

{% hint style="success" %}
check whether an object has a [**property**](/web/js/val/obj/prop.md).

```javascript
'prop' in obj                     // in operator
Object.hasOwn(obj, 'prop')        // recommended
obj.hasOwnProperty('prop')        // not recommended
obj.propertyIsEnumerable('prop')
```

{% endhint %}

:star: the following methods/operators all support [**String**](/web/js/val/prim/str.md) <mark style="color:yellow;">**/**</mark> [**Symbol**](/web/js/val/prim/symbol.md) keys.

<table><thead><tr><th>method/operator</th><th width="110">own enum<select><option value="fa493c02131745babc72fa4cfd60f1bf" label="✅" color="blue"></option><option value="575cf73897dd4bbab4db839c76bf6f75" label="❌" color="blue"></option></select></th><th width="105">own nonenum<select><option value="92aacf9c25cc45758898e9cea377838c" label="✅" color="blue"></option><option value="186e2fd65cb541ed828129ae4de3338d" label="❌" color="blue"></option></select></th><th width="105">inherited enum<select><option value="ae58de58a03140a1ac9a7bb88c048855" label="✅" color="blue"></option><option value="ca78ad327cf849e5921fd1334fab4b59" label="❌" color="blue"></option></select></th><th width="107">inherited nonenum<select><option value="2029a71aaf8c4baaac53af637338d80b" label="✅" color="blue"></option><option value="50730b3459424472be062a6ecb9f9fad" label="❌" color="blue"></option></select></th></tr></thead><tbody><tr><td><a href="/pages/yFPMDvfgLWvBWu54f66H">in</a></td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td><span data-option="ae58de58a03140a1ac9a7bb88c048855">✅</span></td><td><span data-option="2029a71aaf8c4baaac53af637338d80b">✅</span></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn">.hasOwn()</a></td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty">.hasOwnProperty()</a></td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td><span data-option="92aacf9c25cc45758898e9cea377838c">✅</span></td><td></td><td></td></tr><tr><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable">.propertyIsEnumerable()</a></td><td><span data-option="fa493c02131745babc72fa4cfd60f1bf">✅</span></td><td></td><td></td><td></td></tr></tbody></table>

{% tabs %}
{% tab title="⭐️" %}
{% hint style="success" %}
Every [**property**](/web/js/val/obj/prop.md) in JavaScript [**objects**](/web/js/val/obj.md) can be <mark style="color:yellow;">**classified by**</mark>**&#x20;**<mark style="color:orange;">**3**</mark>**&#x20;**<mark style="color:yellow;">**factors**</mark>:

* [**String**](/web/js/val/prim/str.md) <mark style="color:yellow;">**/**</mark> [**Symbol**](/web/js/val/prim/symbol.md)
* <mark style="color:orange;">**enumerable**</mark>**&#x20;**<mark style="color:yellow;">**/**</mark>**&#x20;**<mark style="color:orange;">**non-enumerable**</mark>
* <mark style="color:orange;">**own**</mark>**&#x20;**<mark style="color:yellow;">**/**</mark>**&#x20;**<mark style="color:orange;">**inherited**</mark> (from the [**prototype chain**](/web/js/val/obj/proto/chain.md))

📘 [MSN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties)&#x20;
{% endhint %}
{% endtab %}

{% tab title="🔴" %}

* [in](/web/js/grammar/op/relational/in.md) operator
* [for-in vs. for-of vs. in](/web/js/grammar/statement/loop/for/for-in-vs.-for-of-vs.-in.md)
  {% endtab %}

{% tab title="👥" %}

* [property enumeration](/web/js/val/obj/prop/enumerate.md)
* [**Proxy**](/web/js/val/builtin/proxy.md) intercepts <mark style="color:purple;">**property testing**</mark>.
  {% endtab %}

{% tab title="📗" %}

* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 6.5 Testing Properties
  {% endtab %}

{% tab title="📘" %}

* [ ] [Enumerability and ownership of properties ⭐️ ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties)
* [ ] Object.prototype ⟩ &#x20;
  * [ ] [.hasOwnProperty()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
  * [ ] [.propertyIsEnumerable()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
* [ ] Object ⟩&#x20;
  * [ ] [.hasOwn()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
  * [ ] [.getOwnPropertyNames()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
* [ ] [for...in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
* [ ] [in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in)
* [ ] [JavaScript Guide: Inheritance revisited](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/obj/prop/test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
