Let's take this for example:
function test(i, total) {
return total + i * 100 / 999 * -124 / 333;
}
var total = 0;
for (var i = 0; i <= 100; i++) {
total = test(i, total);
console.log(total);
}
When testing it, I see that it works synchronously -- the for loop will wait until test(i, total) has returned its value before going through the next iteration.
However there are other cases where a loop would keep on going and even finish, before a function was even done doing its function. If the test function took 3 seconds to return, why does the loop wait on that? Is it because there is nothing of async nature in the test function? I tried setting a setTimeout of 3 seconds in the test function and then I'd get undefined from the console log.