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

Inside JavaScript if Object and Function are both defined as functions then what is their relation to each other and how are both instances of each other?

I don't understand if Object is at the top most position in JavaScript and how Function also inherits from Object..

6
  • 1
    Looks like a duplicate of this: stackoverflow.com/questions/29813074/… Commented Jul 19, 2016 at 21:20
  • 2
    "they both are instanceof of each other" - not interesting. Function is an instance of itself, now take that! (And ordinarily, every function is also an object) Commented Jul 19, 2016 at 21:21
  • @Bergi thanks for reply Commented Jul 19, 2016 at 21:24
  • From my professor's slides: "Function objects are linked to Function.prototype (which is itself linked to Object.prototype)" cit.dixie.edu/cs/4010/functions.pdf And cit.dixie.edu/cs/4010/objects.pdf Commented Jul 19, 2016 at 21:28
  • One of the best resources I have found for these types of questions is David Herman's Effective JavaScript. It's the one reference I go back to the most. Commented Jul 19, 2016 at 21:46

1 Answer 1

1

I think you may be getting confused between the value Object and objects in general. You may be thinking from what you see above that this means that "all objects are functions" but this is not true.

All functions are objects. The values Object and Function are both (constructor) functions, so they are both objects as well. In other words, they are both instances of Object and Function.

Perhaps you'll find this a bit more illuminating:

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

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

console.log(new Object() instanceof Function);   // false
console.log({} instanceof Function);             // false
console.log(new Function() instanceof Function); // true
console.log(function(){ }  instanceof Function); // true

console.log(new Object() instanceof Object);     // true
console.log({} instanceof Object);               // true
console.log(new Function() instanceof Object);   // true
console.log(function(){ }  instanceof Object);   // true

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.