0

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

user2613946
  • 435
  • 2
  • 7
  • 17
  • 1
    Does this answer your question? [How does JavaScript .prototype work?](https://stackoverflow.com/questions/572897/how-does-javascript-prototype-work) – InSync Jun 05 '23 at 00:56
  • 1
    Namely, [this answer](https://stackoverflow.com/q/572897) and [this one](https://stackoverflow.com/a/35458348/21305238) which is linked from the former. – InSync Jun 05 '23 at 00:57

2 Answers2

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
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

JulienBrks
  • 27
  • 4