1

I'm trying understand core javascript. it's little bit confusing. When I evaluate

Object instanceof Function

its true , and Function instanceof Object its also true.

How and why?

6
  • Object and Function both refer to functions. Your question is confusing; you should re-read it. Commented Jan 7, 2015 at 18:09
  • You said you evaluated Object instanceof Function twice in your question. Commented Jan 7, 2015 at 18:10
  • Hint: evaluate Object and see what it returns. Commented Jan 7, 2015 at 18:11
  • You can have a look into this link .. stackoverflow.com/questions/14162038/… Commented Jan 7, 2015 at 18:11
  • 1
    It's probably good to know at this point how obj instanceof Func works. It simply checks whether Func.prototype is in obj's prototype chain. Since Object is a function, Function.prototype is in its prototype chain. Since Function is an object (every function is an object), Object.prototype is in its prototype chain. Commented Jan 7, 2015 at 18:14

1 Answer 1

1

Becouse instanceof is evaluating Object and checking if this has as an instance of Function.constructor in its prototype chain, and reverse:

Function.__proto__.__proto__ // Object.prototype
Object.__proto__ // Function.prototype

Anyway, you have the full explanation on this answer.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't explain why Object is an instance of Function.
And of course, Object is a function

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.