i am using
var foo = function(){}
typeof(foo) - returns function instead of Object
while javascript concept tell that all function in javascript are objects?
First and foremost, there's the fact that the specification explicitly states they're objects, in a lot of places, including here where it defines the term "function":
function
member of the Object type that may be invoked as a subroutine
Empirically, there are lots of ways to prove it, but one of the simplest is to assign a value to a property on it:
var foo = function() { };
foo.myProperty = "my value";
console.log(foo.myProperty); // "my value"
Or use one as a prototype (which is unusual, but possible), which proves it as only objects can be prototypes:
var foo = function() { };
var obj = Object.create(foo);
console.log(Object.getPrototypeOf(obj) === foo); // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With