Dont understand what "callback" mean

Tell us what’s happening:
Describe your issue in detail here.

What i think is callback is a function parameter, why it can using ( ) ??? like callback() thats illegal for me lol.

and secondly
const new_s = s.myMap
(function(item) { return item * 2; } ) ;
why item. This parameter can detect newArray[i] .I dont pass anything to it to reference.

I am confuse.

  **Your code so far**
// The global variable
const s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
for (let i = 0; i < this.length; i++)
{ 
   newArray.push(callback(this[i]));
}

// Only change code above this line
return newArray;
};

const new_s = s.myMap(function(item) {
return item * 2;
});
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

Challenge: Implement map on a Prototype

Link to the challenge:

Yes, callback is here a function. In javascript functions can accept other functions as parameters.

For your second question. the function, that’s passed to the s.myMap(func) is the function that’s later used as a callback.

1 Like

thank you,so the concept now i need to know is how callback work right?

1 Like

Kind of. This is a bit abstract though. After all it can be any function, that will do what is expected of it. In here that’s accepting one argument and returning something.