Consider:
(function(){
console.log(1);
setTimeout(function(){console.log(2)},1000);
setTimeout(function(){console.log(3)},0);
console.log(4);
})();
The code written above outputs:
1
4
undefined
3
2
What is happening behind the scene, as I can understand setTimeout function is delaying it by 1 sec and 0 sec?
Why it is printing out undefined?