Search e01
One query across the encyclopedia, books, dictionary, papers, Wikidata and the developer library. Every hit carries its source.
6 results across 6 corpora for Object.prototype.hasOwnProperty().
Developer library 6
Guidelines for writing JavaScript code examples
```js example-bad const obj = { foo: function () { // … }, bar: function () { // … }, }; ``` ### Object properties - The [`Object.prototype.hasOwnProperty()`](/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) method has been deprecated in favor of [`Object.hasOwn()`](/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn). - When possible, use the shorthand avoiding the dup
Object prototypes
and `greet`, there are lots of other properties! ```plain __defineGetter__ __defineSetter__ __lookupGetter__ __lookupSetter__ __proto__ city constructor greet hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf ``` Try accessing one of them: ```js myObject.toString(); // "[object Object]" ``` It works (even if it's not obvious what `toString()` does). What are these extra properties
Object
rototypeOf() alternatives are static methods. - The [`propertyIsEnumerable()`](/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable) and [`hasOwnProperty()`](/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) methods can be replaced with the Object.getOwnPropertyDescriptor() and Object.hasOwn() static methods, respectively. - The [`isPrototypeOf()`](/docs/Web/JavaScript/Referenc
Object.hasOwn()
. If the property is inherited, or does not exist, the method returns `false`. > [!NOTE] > `Object.hasOwn()` is intended as a replacement for Object.prototype.hasOwnProperty(). JavaScript Demo: Object.hasOwn() ```js interactive-example const object = { prop: "exists", }; console.log(Object.hasOwn(object, "prop")); // Expected output: true console.log(Object.hasOwn(object, "toString")); // Expected output: fals
Object.prototype.hasOwnProperty()
The **`hasOwnProperty()`** method of Object instances returns a boolean indicating whether this object has the specified property as its own property (as opposed to inheriting it). > [!NOTE] > Object.hasOwn() is recommended over > `hasOwnProperty()`, in browsers where it is supported. JavaScript Demo: Object.prototype.hasOwnProperty() ```js interactive-example const object = {}; object.foo = 42; console.log(objec
in
ts to store arbitrary key-value pairs. ```js example-bad const ages = { alice: 18, bob: 27 }; function hasPerson(name) { return name in ages; } hasPerson("hasOwnProperty"); // true ``` You can use Object.hasOwn() to check if the object has the key. ```js const ages = { alice: 18, bob: 27 }; function hasPerson(name) { return Object.hasOwn(ages, name); } hasPerson("hasOwnProperty"); // false ``` Alternative