Contact List


Hi ,
i have two questions for my doubt:

1 i want to know why : for(var firstName in friends)
i considered that only one way to expression :for(var i=0,i++;i<string.length)
why it works for(var firstName in friends) ?
2 use the var list = function(friends) two times ?
i could not understand this

friends.bill=new Object();

friends.steve=new Object();
var list=function(friends){
for(var firstName in object)
var myString = "Hey";
var list = function(friends) {
for(var firstName in friends) {


Is there code missing?

Also, will you copy the link to the question?


no,it passed the lesson ,as i saw the code of another ,
i donot understand the code .this is why i wrote here


It looks incomplete and it's hard to tell the context of this code.

You should be able to go back to that lesson and paste the link here.

this is the link .but the codes are not problem .
i just donot understand the code .
thank you for your help .


This was looking weird because you never actually call the functions, so I was wondering how you were getting anything to output. I now see that it is part of the exercise.

Answer to Question 1

General for loop rule:

  • User "for in" loops for objects

    • These are situations where the amount of members in object are NOT KNOWN

  • Use "for" loops for arrays

    • These are situations where the amount of members in object are KNOWN

    • Array have access to the .length property to identity the amount of members in the array

for in works in this case because:

  • the friends object has 2 members: bill and steve

  • for in will iterate over all members in the object

for will not work in this case because:

  • there is no way to know how many members are in the objects without knowing ahead of time
    How will you know when to end the for loop?

Answer to Question 2

There is no need for two functions to be assigned to the variable list. The first assignment to list would:

  1. only print undefined two (2) times, because console.log() is not given a parameter.

  2. be overwritten by the second assignment to list

It is important to know that list is not being used by you. In order to use it you would have to call it similar to:


There is some test code in the background of the exercise that is running your code. This is why it is important to use the same object and function names (e.g., friends, friends.bill, friends.steve, list and etc) that they provide in the exercise.

Does this help?


thank you for helps .


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