1

In Chrome,

Object.__proto__ returns ƒ () { [native code] }

whereas

Function.__proto__.__proto__.__proto__ returns null

Also, typeof Object is Function.

If type of Object is Function, Isn't everything in JavaScript a function?

I'm a newbie, Please help me out...

1 Answers1

0

__proto__ is a getter/setter on Object.prototype which can get the object's internal prototype (if gotten), or set it (if set).

For Object.__proto__, Object is a constructor function, and all functions have an internal prototype of Function.prototype, so that's what you're seeing:

console.log(Object.__proto__ === Function.prototype);

The prototype chain is:

null <- Object.prototype <- Function.prototype <- Object

In contrast, with:

Function.__proto__.__proto__.__proto__ 

The prototype chain is:

null <- Object.prototype <- Function.prototype <- Function 

So, access __proto__ 3 times from Function, and you get to null.

If type of Object is Function, Isn't everything in JavaScript a function?

Object is a function only because it's possible to call it as a constructor (which is a very weird thing to do in most cases, but it's technically permitted by the language).

const doNotDoThis = new Object();

Object is a constructor - this is very different from Object.prototype, which is a plain object. Most non-primitives inherit from Object.prototype, but only functions inherit from Function.prototype.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320