6. List ‘em all - code works, but how?


#1



https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/6


My code does work correctly, but there is one aspect that I don't understand, I'll explain:

So I've made the friends object, and made two objects within that, with keys.

Then I write this piece of code:

var list = function (obj) {
for (var i in obj) {
console.log(i);
}
};

and the names 'bill' and 'steve' get printed, as expected. But how come the function knows how to use the object 'friends'? I did not specify that. Can onyone explain me that?

Thank you


var friends = new Object();
    
    friends.bill = new Object();
    friends.steve = new Object();
    
    friends.bill.firstName = 'Bill';
    friends.bill.lastName = 'Gates';
    friends.bill.number = '0611833845';
    friends.bill.address = ['Microsoft Way 1','2455HH','Dordrecht'];
    
    friends.steve.firstName = 'Steve';
    friends.steve.lastName = 'Jobs';
    friends.steve.number = '0622222222';
    friends.steve.address = ['Straat 3','233HH','Dordrecht'];
    
var list = function (obj) {
    for (var i in obj) {
        console.log(i);
    }
};


#2

Hello @blogmaster83388,

Your code is deploying the names even though you haven't specified anything because that is just Codecademy checking the validity of your code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.