6. List Em All - Explanation


#1

Can some one explain what is happening with the list function that results in the output? I don't get how it knows to Output "Bill" "Steve" ...and all of a sudden, "Steves's info". Please explain!!

var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(408) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']
};
var list = function(friends) {
for (var friend in friends) {
console.log(friend);
}
};

OUTPUT

bill
steve
{"firstName":"Steve","lastName":"Jobs","number":"(408) 555-5555","address":["1 Infinite Loop","Cupertino","CA","95014"]}


#2

Have you tried manually calling list(friends) after defining the function and seeing if the output changes? I know some interpreters can output data like that to the console if there's no function to call.