What does the HasOwnProperty anti-pattern refer to, and what is the safer alternative?

JavaScript Professional Hard

JavaScript Professional — Hard

What does the HasOwnProperty anti-pattern refer to, and what is the safer alternative?

Key points

  • Object.hasOwn(obj, key) is the safe alternative
  • obj.hasOwnProperty(key) can fail in certain scenarios
  • Object.create(null) can cause issues with hasOwnProperty

Ready to go further?

Related questions