Home > Enterprise >  Difference between __proto__ and [[prototype]] in Global-Object?
Difference between __proto__ and [[prototype]] in Global-Object?

Time:02-05

In Browser there are some Global-Objects pre-built (Objects, String, Number, Date, etc). Mother of all such global-objects is "Object". As, this Object is the prototype of nearly all of the data-types present in JS (except only 2 - null and undefined).

Now, we move up after creating any variable of any data-type, we'll use __proto__ to climb up the chain. But, when we react the "Object", the __proto__ points to null and "prototype-chain" has an ending!

Till now I thought prototype and __proto__ are one and the same. Today, I went and found, that in the Global-Object, while __proto__ points to null,[[prototype]] (inside get proto & set proto) consists of heaps of other values.

Can someone differentiate to me, what exactly is the difference between __proto__ and [[prototype]] and why the values inside both are completely different? While I thought both things are 1 and the same!

enter image description here

I also read this: devtools screenshot of the text below

>  const obj1 = {example: "x"};
<- undefined
>  obj1
<- {example: 'x'}
      example: "x"
      [[Prototype]]: Object
>  Object.getPrototypeOf(obj1) === Object.prototype
<- true
>  Object.getPrototypeOf(obj1) === obj1.__proto__
<- true
>  obj1.prototype
<- undefined

(One part of that which could be confusing is where is says [[Prototype]]: Object. The devtools show the name of the constructor for an object. The [[Prototype]] of the object is the object referenced by Object.prototype, not the Object constructor itself.)

  •  Tags:  
  • Related