Why does the output give me the last line of my friends.soandso code?


The code here works fine, but when it runs it'll print out "bill, steve, brian, john" just fine, but it will also include the last array in the friends.john.address line. It will look like this:

["3 Carolina Avenue","Greenville","SC","48876"]

Why does it do that?

var friends = new Object();
friends.bill = new Object();
    friends.bill.firstName = "Bill";
    friends.bill.lastName = "Gates";
    friends.bill.number = "(505) 555-5555";
    friends.bill.address = ["1 Microsoft Road", "Redmond", "WA", "20089"];
friends.steve = new Object();
    friends.steve.firstName = "Steve";
    friends.steve.lastName = "Jobs";
    friends.steve.number = "(606) 555-5555";
    friends.steve.address = ["1 Apple Drive", "Cupertino", "CA", "10098"];
friends.brian = new Object();
    friends.brian.firstName = "Brian";
    friends.brian.firstName = "Kaplan";
    friends.brian.number = "(770) 555-5555";
    friends.brian.address = ["7 Atlanta Lane", "Roswell", "GA", "33075"];
friends.john = new Object();
    friends.john.firstName = "John";
    friends.john.lastName = "Elliott";
    friends.john.number = "(445) 555-5555";
    friends.john.address = ["3 Carolina Avenue", "Greenville", "SC", "48876"];

var list = function(friends) {
    for (var key in friends) {


Normally, this line would not be printed. This is a feature of interactive environments, it is a very helpful feature.

So, how it works? It simply prints out to the console value returned by the last evaluated statement. In this case, it is this statement:

friends.john.address = ["3 Carolina Avenue", "Greenville", "SC", "48876"];

This is assignation and assignation returns the assigned value, example:

var a;
console.log(a = 318);

Output of this code is 318.

In normal environments, this line of output is marked with the special indicator, usually =>. In codecademy you just have to get used to that :slight_smile:


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