-1

How passing cats to func returns a callback?

let animal = '';
const fetchAnimal = func => {
  func('cats');
};

fetchAnimal(name => {
  //logs cats to the console
  console.log(name);
});
sbrk
  • 3
  • 1
  • 2

1 Answers1

0

Well here we are passing a function as parameter to fetchAnimal in the function call which is mapped to func variable. so when you call func('cats') it's eventually calling the function you passed during the function call with cats as parameter which maps to variable name.

const fetchAnimal = func => {
  func('cats');
};

fetchAnimal(name => {
  console.log(name);
});
Code Maniac
  • 37,143
  • 5
  • 39
  • 60