# property testing

* [JS](../../..) ⟩ [value](../..) ⟩ [object](..) ⟩ [property]() ⟩ testing properties&#x20;

{% hint style="success" %}
check whether an object has a [**property**]().

```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**](../../prim/str) <mark style="color:yellow;">**/**</mark> [**Symbol**](../../prim/symbol) 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="../../../grammar/op/relational/in">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**]() in JavaScript [**objects**](..) can be <mark style="color:yellow;">**classified by**</mark>**&#x20;**<mark style="color:orange;">**3**</mark>**&#x20;**<mark style="color:yellow;">**factors**</mark>:

* [**String**](../../prim/str) <mark style="color:yellow;">**/**</mark> [**Symbol**](../../prim/symbol)
* <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**](../proto/chain))

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

{% tab title="🔴" %}
* [in](../../../grammar/op/relational/in "mention") operator
* [for-in-vs.-for-of-vs.-in](../../../grammar/statement/loop/for/for-in-vs.-for-of-vs.-in "mention")
{% endtab %}

{% tab title="👥" %}
* [enumerate](enumerate "mention")
* [**Proxy**](../../builtin/proxy) intercepts <mark style="color:purple;">**property testing**</mark>.
{% endtab %}

{% tab title="📗" %}
* [ ] [javascript-the-definitive-guide](../../../../master/ref/javascript-the-definitive-guide "mention") ⟩ 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 %}
