7/8 Search names - Where did name in "var search = function(name)" came from?


I understand 99% of a code, but I have no idea where is program find a name.
There is only firstName and lastName.
No var called name is in the code before creating a function.

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: 234567,
address: ['one', 'street', '2345']

steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: 2134,
    address: ['asd','saf']


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

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


Name is just a convention variable name for a function. It just as easily could've been x or n, it's only to help you remember what data your function uses.


So when the script workes, where is it finding input for the search function? Could I leave it empty?


It is where you call it, for example you call:


No, you cannot leave it blank.


I still don't uderstand, in all the functions from previous lessons I had to put there some var that exists and has some value. In here I do not see any value inside this name var. Is it an empty var, or is scrip connecting it to the objects?


It is nothing, it just lets you know that your function needs information to run.


So let's say it is a part of syntax that has to be there, but is not doing anything in this script?


I think you should read this:

MDN - Functions


Name is the argument that the function is taking/expecting. It does not have a value until you pass in an argument when calling the search function, for example:


would assign "Hello!" to greeting in:

var yourFunction = function (greeting) {consol.log(greeting)}; // would print "Hello!"