Lesson 6 - Printing stuff it shouldnt


#1

Ok, i got a question about this lesson...

Here is my code:

var friends = new Object();
    friends.bill = new Object();
        friends.bill.firstName = "Bill";
        friends.bill.lastName = "Gates";
        friends.bill.number = "25151515";
        friends.bill.address = ["blabla street","number 9","noonecares"];
    friends.steve = new Object();
        friends.steve.firstName = "Steve";
        friends.steve.lastName = "Jobs";
        friends.steve.number = "55555555";
        friends.steve.address = ["whatever street","number 7","whocares"];
        
var list = function(friends){
    for (var naem in friends){
        console.log(naem);
    }
}

The console is printing:

bill
steve
["whatever street","number 7","whocares"]

Why is he printing that last line?


#2

I am having a similar piece of code and first I am asking the same question as lowisinferno, then I start doubting if I actually understand the concepts of functions.

Why is it printing out anything at all, doesn't the function need to be called first? Or is it that there is a parameter in the definition of the function that calls the function? What is the deal.

Please can someone break down the code for me when it comes to the function and for... in.

Thank you!


#3

When I test it in the Codeacademy editor it prints it out twice. However, if I test it in the browser it works fine.

Your code is completely correct lowisinferno.