console.time("Time");
var i=0;
setTimeout(function(){console.log("Timeout...")},500);
while(true){
if(i==1000000000){
console.timeEnd("Time");
console.log("whileloop breaking...");
break;
}
else{i++;}
}
In this code i'm trying to print Timeout in console after 0.5 second, and there is a while loop which terminates after a time of around 2 seconds which i'm showing through logging the time spent. I expected Timeout to print first as it completes in 0.5 seconds and the whileloop breaking should print which takes more time, but it's printing whileloop breaking first and then going for Timeout...can anyone explain stack trace or flow of this code.