setTimeout(() => {
console.log('1st callback function');
}, 1000);
fetch('https://api.netflix.com').then(() => {
console.log('2nd callback Function');
});
These both are the Callback Function but as i heard that setTimeout callback function will go inside the Task queue/Callback queue and fetch Callback function is go inside the Micro Task Queue. so what the reason behind this?
setTimeout()resolves faster than thefetchit will come first however functions likefetchthose returns promises get registered to the micro task queue and have precedence over the event queue. However this is only a choice when they get resolved at the same time.