General questions regarding "list" and "search" functions


#1

In general i do not feel i completely understand the logic behind them, but specifically things like the words "prop" and "obj" are confusing. I know they are random names given to a variable we have created, but I especially don't understand what "prop" does (the defined variable inside the for function).

I have included the code in question below, it is coped out from the first page of the exercise, any insights or logical ways of viewing this would be greatly appreciated.

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

var search = function(name) {
  for(var prop in friends) {
    if(friends[prop].firstName === name) {
      console.log(friends[prop]);
      return friends[prop];
    }
  }
};`

#2

I will try to explain this, even though I'm as much of a journeyman as you are. Lets use shorter list function as an example:

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

Function list takes 1 parameter, an Object, that is called obj. It's just a unique identifier (or variable name, if you prefer) that could have any other name as any other variable. Nothing fancy here.

prop is shorthand of property, since Objects have properties. I believe this is the main reason why it is used in the given example, since we are iterating through Objects' properties with for in loop. Basically, it could have been any other name. I used "v". It's totally up to you. Remember for loops with variable i? Well, same goes here.