var obj = {};
var fn = function(){};
obj.prop = "some value";
fn.prop = "some value";
assert( obj.prop == fn.prop, "Both are objects, both have the property." );
assert(typeof(obj) === 'object', "Yes its an object");
assert(typeof(fn) === 'object', "why is this not an object");
I heard from some people around that functions are objects and this is what i am believing so far, but why is the first condition passes well and third one fails.
That’s because the direct type of a function is
"function".However, you missed this assertion:
Btw, types such as
"number"and"string"are strictly not descendants ofObject, even though they are like objects in the sense that they have methods; just one of those things that makes JavaScript interesting 🙂See also:
typeofand its range of values.