Predict the output of the following javascript code
(function(){
setTimeout(()=> console.log(1),2000);
console.log(2);
setTimeout(()=> console.log(3),0);
console.log(4);
})();
Quiz Explanation
Console logs 2 first, then despite a 0ms delay, 4 appears before 3 due to setTimeout executing in the Web API. Finally, after a 2000ms delay, 1 is printed