var a = [1,2,3,4,5,6,7,8,9,10];
a.forEach(item => {
...
});
console.log('all done');
Is it ever possible in browser or node environment that it console 'all done' before the forEach completes its execution? If yes then when?
var a = [1,2,3,4,5,6,7,8,9,10];
a.forEach(item => {
...
});
console.log('all done');
Is it ever possible in browser or node environment that it console 'all done' before the forEach completes its execution? If yes then when?
No. Your code is synchronous so it can never happen unless you explicitly execute the .forEach
function in an async block.
No. forEach
is a synchronous function.
It is possible to call asynchronous functions from within it, and they might not have completed, but the loop itself will have done.