DEV Community

Bruno Moura
Bruno Moura

Posted on

[Javascript] - Data dictionary

Object.create() // TypeError: Object prototype may only be an Object or null
Enter fullscreen mode Exit fullscreen mode
Object.create(null) //[Object: null prototype] {}
Enter fullscreen mode Exit fullscreen mode
Object.create({}) // {}
Enter fullscreen mode Exit fullscreen mode

The second one is a data dictionary, because it is an object without a parent.

It creates an object that has an empty [[Prototype]] binding (also known as null), and therefore this object cannot delegate anywhere.

As an object of this type does not have a prototype chain, the instanceof operator has nothing to check, so it will always return false.

These special empty [[Prototype]] objects are often called "dictionaries" as they are typically only used to store data in properties, most of the time because they have no surprise effect coming from any delegated property/function in the chain [[Prototype]], and therefore are only used for data storage.

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

Constructors, in javaScript, it is more appropriate to say that, a "constructor" is any function called with a "new" keyword before it. Functions are not constructors, but function calls are "constructor calls" if and only if "new" is used.

Top comments (0)