Javascript vs Function Object

I am new to JavaScript based on the Java background. I find it difficult to understand the following behavior.

console.log(Object.constructor.name); // prints Function.

console.log(Object instanceof Function); // prints true since Object constructor is Function.

So this means that Object is an instance of Function.

console.log(Function instanceof Object); // prints true

How can a function be an instance of Object if Object is an instance of Function?

I ran the code in the latest Chrome Chrome browser.

+4
source share
1 answer

Both Objectand Functionare constructors, so they are functions.

The expression Object instanceof Functionreturns truebecause it Objectis a function, therefore it is an instance of the type Function.

Function instanceof Object true, Function - , Function, Object.

+2

All Articles