There is such an example in javascript:
var fruits = ['apple', 'banana', 'orange', 'grapes', 'pear', 'passionfruit']; // The three values on the callback function are: // element - The element being traversed // index - The current index of the item in the array starting at 0 // array - The array being traversed (probably mostly irrelevant) fruits.forEach(function(element, index, array) { console.log(index, element); }); a forEach is passed to the forEach method. I understand that somewhere in the forEach method this passed function is called. To call it, you need to pass 3 arguments to it (preferably). The people who wrote the code for this function somehow sort through the elements of the fruits array and call my callback function, passing all these three parameters to it. How do they know what is in what place? After all, in fact, I can not write
function(element, index,array) but
function(myelement, myindex,myarray) those. change the name of the parameters and will still work. It turns out that the elements passed to the function are "tied" to the place of the parameter - 1, 2, 3 in the account. So? Or somewhere I'm wrong. Tell me please?
I will carry the question separately:
are the parameters passed to the callback function "tied" to the place of the parameter?