Having an object like this:
var a = {
b: "string",
c: function(){
return "i return a string";
}
}
Doing
for (var key in a) {
console.log(typeof key);
};
Returns “string”, “string” since b is a string and c returns a string.
Is there afunction that returns c -> function?
No. The reason it returns
string, is that the attribute nameband the attribute namecare both strings; you’re iterating over the keys of the object, not their values right now.You could introduce attribute
d, which was a function which returned a number or boolean, and you’d still getstring.Instead, enumerate over the values themselves;