When would you want to use Object.create(null) instead of {} to create a new object?

  • When you need an object with no prototype chain to avoid inheriting properties or methods unintentionally.
  • When you want an object that can't be modified or extended further.
  • When you need an object with a predefined set of properties and methods for a specific use case.
  • When you want to create an empty object with the default prototype chain.
Object.create(null) is used when you need an object with no prototype chain (a "null prototype"), which means it won't inherit any properties or methods from Object.prototype. This can be useful for creating objects where you want complete control over the properties and avoid unintentional inheritance.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *