I want to run a function namely 'callbackfn' after the setTimeout function is being executed .If i run it in my global execution context then only when the code inside callbackfn is being executed then setTimeout Function will run as it will go inside callback queue and will be on hold until the lines in the global execution context.
But what i want is to execute callbackfn after the setTimeout is being executed.For that i have to push the callbackfn inside callback queue.So,how can we explicitly push it inside callback queue.
You can pass the callbackfn as third parameter to the setTimeout. The callback function will execute once the setTimeout function runs.
function callbackfn() {
console.log('func is executed');
}
setTimeout(function(callback) {
callbackfn();
}, 3000, callbackfn);
The short answer is you can't push your function directly to the queue without something like setTimeout. to understand why you should know