DEV Community

Cover image for Creating JS objects that has no prototype
Taslan Graham
Taslan Graham

Posted on

Creating JS objects that has no prototype

We know that All JavaScript objects inherit properties and methods from a prototype.

For example:
Date objects inherit from Date.prototype
Array objects inherit from Array.prototype

What if you want to create an Object that does not have a prototype?
Here's a neat little way to do it:

const blankObject = Object.create(null)
Enter fullscreen mode Exit fullscreen mode

When creating objects using Object.create(), we can pass an object which will be used as the prototype for the newly created object. Alternatively, we can pass null which will result in an object being created without a prototype.

I only came across this recently. I think it's pretty cool and I may find some use for it.

Top comments (2)

Collapse
 
bias profile image
Tobias Nickel

you asked it yourself,... why?

Collapse
 
taslangraham profile image
Taslan Graham

no reason in particular. Just found it interesting.