let fn_one = () => {
setTimeout(function() {
console.log("This is shashank");
}, 5000)
}
let fn_two = (name, callback) => {
setTimeout(function() {
console.log("Hi!, " + name);
callback();
}, 1000)
}
fn_two("there", fn_one)
Here, fn_two
is called and it executes after one second, however, it has a callback function which is set to fn_one()
. So it should call the callback function immediately after it executes the fn_two
function, right? Why is it taking 5 seconds after the fn_two
is called? Why is it not working in background?
Can anyone explain to me why the function fn_one
is taking 5 seconds even though I have called it as a callback function?