1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.