I'm creating a simple callback function trying to understand how it works.
function cbFunction(x, y, z) {
return x + y + z
}
function caller(x, y, z, cbFunction) {
console.log('In caller function!')
// your code here
if (typeof cbFunction === "function") {
cbFunction (x, y, z)
}
}
caller(1, 2, 3, cbFunction)
I'm invoking the cbFunction inside the caller function. Could you help me to understand why it isn't adding x, y, z? I'm learning JS as a beginner and thank you for your help!
callerdoesn't care about the return value either.cbFunction, you could tryreturn cbFunction(x, y, z)in the caller functionthenconsole.log(caller(1, 2, 3, cbFunction));