JS Built-ins
← Object124 / 150
ObjecthasOwnPropertybeginner

hasOwnProperty() β€” after delete

πŸ“– Usage Example
// Check for own (non-inherited) property
const obj = { a: 1 }
obj.hasOwnProperty('a')          // β†’ true
obj.hasOwnProperty('toString')   // β†’ false

Use hasOwnProperty() to check whether a property exists directly on an object rather than on its prototype chain.

hasOwnProperty() β€” after delete

Once a property is deleted with the delete operator, hasOwnProperty() returns false for it.

Challenge: Delete a property and verify it's gone using hasOwnProperty().

πŸ’‘ Hints (1)
  • β€’ delete removes the property from the object entirely