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...

2
  • 1
    Object is a constructor, which is a function. Commented Apr 8, 2021 at 1:52
  • I'm having a hard time understanding the context of your question. Where do the code snippets come from? Are they the result of a console.log? Commented Apr 8, 2021 at 1:52

1 Answer 1

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.

answered Apr 8, 2021 at 1:55
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.