skip to Main Content

When we create an object and look at the [[prototype]] of it, there is a __proto__ property and even further we expand there is the same set of properties with another __proto__ but with the null value.

What is the reason for these two levels of __proto__ and why it is null in the second occurrence?

enter image description here

2

Answers


  1. Let’s take an example to illustrate what happens internally:

    1. Define an ordinary object a const a = {} which is Sugar syntax for const a = new Object()

    2. new operator points a[[prototype]] to Object.prototype. a[[prototype]] = Object.prototype

    3. Object.prototype has a [[prototype]] which value is null

    4. So a[[prototype][[prototype]] => Object.prototype[[prototype]] => null

    Login or Signup to reply.
  2. Wow, that’s really confusing. __proto__ is a (deprecated) getter/setter, and expanding it in the console will run the getter on the start of the prototype chain. It then returns Object.protype, and expanding __proto__ on that result object will now result in null.

    But my advice is to completely ignore __proto__. It is deprecated and should not be used anywhere, in the console only look at the [[prototype]] which displays the prototype chain links.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search