I came across callback functions in JS and found it to be really amazing. Though there is something about how callbacks behave that i am not able to understand. Example:
function add(num1, num2){
return num1 + num2;
}
function displaySum(num1, num2, callback){
let a = callback(num1, num2)
console.log(a);
}
setTimeout(displaySum(3,5,add), 3000); // This displays the result instantly
And in a similar case
function displayText(text){
console.log('HEY JS');
}
setTimeout(displayText, 3000) //This seems to work
I am not able to understand why is this happening?