var x = {};
x.a = {y:5};
x.b = {z:6};
for (prop in x) console.log(typeof prop); // returns "string". Why not "object"?
Shouldn't it return object? How do I get around this?
If you output the prop's themselves, you'll see they are the keys: "a", "b".
prop gets in the loop are the string "a", and then the string "b"."a" is not an object, it is a string. x.a (or x["a"]) is an object. Have a look at the documentation I linked to in my comment.all of these responses are right, but perhaps you would see it better with a corrected example:
var x = {};
x.a = {y:5};
x.b = {z:6};
for (prop in x) console.log(typeof prop); // returns "string"
for (prop in x) console.log(prop); // returns "a", then "b"
for (prop in x) console.log(typeof x[prop]); // returns "object"
for (prop in x) console.log(x[prop]); // returns {y:5}, then {z:6}
propis: jsfiddle.net/NnLrh/1