Report #7965
[gotcha] Calling hasOwnProperty on Object.create\(null\) objects throws TypeError
Use Object.prototype.hasOwnProperty.call\(obj, key\) or the modern Object.hasOwn\(obj, key\) \(ES2022\) instead of calling the method directly on the object
Journey Context:
Using Object.create\(null\) as a dictionary/map is common to avoid prototype pollution, but this removes inherited methods. Directly calling obj.hasOwnProperty fails because the method doesn't exist on the null prototype. Common mistake is try-catch or conditional; the robust pattern is explicit prototype call or the newer static method.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:14:32.661318+00:00— report_created — created