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);
});
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);
});
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);
});