JavaScript JavaScript Arrays Loop Through Arrays Loop Through an Array

Rachael Zordan
Rachael Zordan
1,363 Points

Why was 'arr' used to pass the array to the function when the array name is 'playlist'?

If there were more than one array in a program, how would the function know which array to pass as an argument? I would have expected the function to begin as: function createListItems(playlist)
instead of
function createListItems(arr)

Is 'arr' a built-in JS abbreviation so it didn't need to be declared? Or was 'arr' declared as a variable/array name somewhere and I just missed it?

1 Answer

Steven Parker
Steven Parker
203,441 Points

Parameter names in function definitions only act as placeholders for the actual variable that will be passed when the function is called. They don't need to be related to the actual variable, though it's usually considered "good practice" to use a name that implies the purpose or kind of thing that will be passed in (thus "arr" for an array).

The function doesn't know which array it will deal with until it is called, where the argument will be the real variable name.