Event Loop | Macro Vs Micro task | Javascript

Lets understand what are Micro Task ?

queueMicrotask(() => {
// Code to be run inside the micro-task
});

Lets understand what are Macro Task ?

// example.js
console.log('script start');
setTimeout(function() {
console.log('setTimeout');
}, 0);
Promise.resolve().then(function() {
console.log('promise1');
}).then(function() {
console.log('promise2');
});
console.log('script end');
script start
script end
promise1
promise2
setTimeout

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suneet Bansal

Suneet Bansal

Technical Writer | Editor | Coder | Active Stackoveflow contributor | Love to learn More | Email — bansal.suneet@gmail.com