I am trying to understand the callback functionality in Javascript. Please find the below code that I have written.
var genericFunction=function(arg1, arg2, callback){
var result=setTimeout(callback(arg1, arg2), 1000);
console.log('Result >> '+result)
return result;
}
var sum=function(arg1, arg2){
return arg1+arg2;
}
console.log(genericFunction(2,5,sum));
console.log('After calling the genericFUnction call.');
I am assuming that the the message After calling the genericFunction call.
should be printed and then later after 10 seconds the value of 7
should be printed. Can you please explain on where I am going wrong?
Here is the jsfiddle