Further understanding, please assist


#1

I have the correct answer, but I need further clarification as to why I used 'return' and console.log within the same function and why the simulator wouldn't just allow me to use console.log().

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

Thanks


#2

If the + operator printed the result to the console instead of returning the result then 1) your console would get spammed and 2) you wouldn't be able to ever add three numbers together, because you can't get ahold of the result of the sum of the first two since + never returns that result.


#3

Sorry, I didn't get it. Can you please simplify your answer? Possibly with an example?


#4

Make a function called add that accepts two arguments and prints the sum.

Now try to compute the sum of three numbers using that function.
You'll find this to be difficult when your printing function doesn't let the rest of your code know what the result was.

add(3, add(8, 4)) // 15


#5

Thanks for the explanation. I got it now.