If the Microtask Queue has more priority than the Macrotask Queue, why the order of console logs is
scriptStart
scriptEnd
setTimeout
Response
instead of
scriptStart
scriptEnd
Response
setTimeout
given that for(let i=0;i<100000000;i++){ const start = Date.now(); }
takes enough time to keep the main thread busy, until the response from fetch arrives?
Full Code
console.log("scriptStart")
setTimeout(() => {
console.log("setTimeout");
}, 0);
fetch("https://jsonplaceholder.typicode.com/todos/1").then(() => {
console.log('Response');
});
for (let i = 0; i < 100000000; i++) {
const start = Date.now();
}
console.log("scriptEnd")