If we run the setTimeout before the for loop (which takes like 5-8 seconds) and run this in chrome dev console the order of execution should be
- First
setTimeout - Second
forloop Finally
console.logsetTimeout(function(){ console.log('setTimeout executes'); },1000); for(var i=0;i<10000;i++){ console.log('inside for loop'); } console.log('after For Loop');
But it doesn't and the order becomes:
- First
forloop - Second
console.log - and finally
setTimeout
Why is this happening?
setTimeout executesmessage should appear first?