As per my knowledge async code is executed when the call stack is empty and execution of the async code is finished in web API
But In a given code why my async code which is
setTimeout function
andPromise
which resolve quickly -- is not getting executed at the mark point<---
at this point call stack is also empty and async code might also have been executed
Function
fu()
is used as a delay so that async code should executed until<----
but output is
after 1
after 1
Test End
Resolve promise1
0 sec timer
console.log('test start');
setTimeout(() => console.log('0 sec timer'), 0);
Promise.resolve('Resolve promise1').then(res => {
mk = 20;
console.log(res);
});
fu();
fu();
// <<---------
console.log('Test End');
As I am in learning stage of JavaScript
so please tell me if I am lagging in tech detail of asynchronous js