0

so I was learning about callback functions, and I was wondering why you can't use parameters in the callback. I explain myself with this code:

function one (name) {
  console.log(`Hey ${name}`);
}
function two (fn){
  console.log('Let me salute you:');
  fn();
}

two(one);

If I try to put two(one('Chris')), won't work, It will give you an error and call the one function first. So, how it should be done? thanks in advance!

Aiden
  • 59
  • 4
  • `one` is a function *reference*, `one('Chris')` is a function *call*. – VLAZ Aug 11 '21 at 19:56
  • `two` needs to take both a function reference and any parameter to pass to it as parameters. – fredrik Aug 11 '21 at 19:57
  • *"So, how it should be done?"* - If you want to add a parameter then you can wrap the function call in a new function. For example: `two(function () { one('Chris'); });` So the `fn` parameter in the `two` function is that outer unnamed (anonymous) function. – David Aug 11 '21 at 19:59

0 Answers0