I was recently tinkering with node js and its asynchronous nature and came across something weird. Here is the code -
let sum = 0;
for(let i=0;i<10000000000;i++){
sum += i
if(i==99999999){
console.log(sum);
}
}
console.log('abc');
By definition of non blocking,it should not wait for the for loop results and should print 'abc' first and then print the value of sum after completion of calculation right? However,this is not happening and the program is waiting for the for loop to finish and print the value of sum and then print 'abc'. Could anyone explain the reasoning behind this? Is this happening due to the way console.log works?