Grokking Advanced JavaScript
0% completed
Async Iteration
A for...of loop does not wait for promises. Given an array of pending promises, it prints the promise objects themselves, not their values:
Promise { <pending> } Promise { <pending> } page 1 page 2
The first loop runs synchronously and finishes before either promise is fulfilled. Node.js prints a pending promise as Promise { <pending> }; a browser console shows it in a slightly different form. The second loop is written for await...of. It awaits each item before the loop body runs, so the body receives the values. Like await, `for await...of
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%