The hasOwnProperty() method is used to determine if an object has a specific property as its direct attribute/own property (not inherited from prototypes). It returns true if the object has the property, and false if it doesn't.
You need to copy only the object's own enumerable properties into a new object. How would you use hasOwnProperty in a loop to achieve this?
If you call obj.hasOwnProperty('toString'), what will be the result when toString is inherited from Object.prototype? Explain why.
We have a function that merges two configuration objects using a for...in loop. It started failing after adding a new prototype method to Object. How would you modify the loop to prevent pulling in prototype properties?
During debugging, you notice that a JSON.stringify call is including unexpected keys from the object's prototype chain. How can hasOwnProperty help you filter those out, and what change would you make in the code?
You are building a utility library that provides a deep clone function. Discuss how you would use hasOwnProperty to correctly traverse objects without copying prototype properties, and any performance considerations for large object graphs.
In a high‑throughput server, you need to validate incoming payload objects against a whitelist of allowed fields. Explain how you would use hasOwnProperty to enforce that only own properties are checked, and what pitfalls to watch for with objects that may have overridden hasOwnProperty.
Your team is refactoring a legacy codebase that heavily relies on for...in loops across many modules. Propose a strategy to replace those loops with safer patterns using hasOwnProperty, considering cross‑team impact, testing, and backward compatibility.
Design a linting rule or TypeScript utility that enforces the use of Object.prototype.hasOwnProperty.call(obj, prop) instead of obj.hasOwnProperty(prop). Explain why this is important in a large monorepo with mixed code styles.