How to Create Pure Objects in JavaScript
When you create new objects in JavaScript β even if it's an empty object β it will have some extra properties and methods that are inherited from the global Object class. You can check what an empty object has in JavaScript by printing it to the console:
When talking about pure objects, we are referring to objects that don't inherit anything and therefore, don't have any additional properties upfront. To create one, we can simply use the Object.create
method, and passing null
to it:
const pure = Object.create(null);
Passing null
to the method call sets what should be the prototype of the object, which in this case, is null
.
Resources:
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: