I'm lerning how callback works, and i'm trying this simple code.
function sayHi(name) {
return `Hi ${name}`;
}
function fetchData(callBack) {
setTimeout(() => {
let name = "Vincenzo";
callBack(name);
}, 2000)
}
console.log(fetchData(sayHi));
Why the return
inside the sayHi
function does not produce any output? instead if i write the code inside a console.log();
it works....
Can anyone explain me this? and how to get the output with the return
?
Thanks!