Some questions about 7/8


#1

I have a question too.

var search = function (name) {
for (var key in friends) {

Why we write here "key" in loop and not a firstName? Because previously I wrote firstName and didn't work. What does "Key" stands for?

if (friends[key].firstName === name) {

What is happening here? Why we write "=== name" and not "=== "Bill" || "Steve" " ? We didn't define anywhere that name = bill or steve so how does it know?

 console.log (friends[key]);
return friends[key];

And finally, why we still have to return here after we log it to the console? Why write both instead of only either console.log or just return?


#2

Hey @limpuls,

I might not have the specific answer you want, but I can give you some. :smiley:

"Key" stands for the things in friends, as said here:

There are only two keys in friends: Bill and Steve.

Remember, as I told you above, there are two keys in friends: Bill and Steve.

What you do is look for the firstName(property) of Bill or Steve:

Then you use name, because name is the parameter in the search function, and at the end you write:

search("Steve")

We are also not able to write

Because then we'll have to write the if statement twice, and we are just doing it the shorter way as shown. :smile: