JS Built-ins
Prototypesintermediate

Prototypes β€” hasOwnProperty for own properties

πŸ“– Usage Example
function Person(name) { this.name = name; }
Person.prototype.greet = function() { return 'Hi, ' + this.name; };
new Person('Alice').greet(); // 'Hi, Alice'

Add methods to a constructor prototype to share them across all instances.

Distinguishing Own Properties from Inherited Properties

The hasOwnProperty() method determines if an object has a property as its own, not inherited from the prototype chain. This is crucial for filtering inherited properties.

Challenge: Use hasOwnProperty() to check if a property belongs to an object itself versus its prototype.

πŸ’‘ Hints (2)
  • β€’ hasOwnProperty only returns true for properties directly on the object
  • β€’ Inherited properties exist but are not own properties