What is the difference between Object.create(null) and {} in JavaScript?
Object.create(null) creates an object with no prototype (no __proto__, no toString, no hasOwnProperty). {} creates an object with Object.prototype as its prototype. Object.create(null) is useful for hash maps where you do not want any inherited properties.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Object.create vs new vs Object.assign in JavaScript
Object.create(proto) creates an object with the specified prototype (no constructor call). new Constructor() calls the constructor function and sets the prototype to Constructor.prototype. Object.create is for direct prototype setting; new is for instantiation.
Copies properties from source objects to a target object (shallow copy). Object.assign({}, defaults, overrides) creates a new object with merged properties. It does not copy inherited properties, only own enumerable properties.
When you want to create an object with a specific prototype without calling a constructor. For example: const dog = Object.create(animal) creates an object that inherits from animal without running any constructor code.
Still have questions?
Browse all our FAQs or reach out to our support team
