JavaScript · Middle · Question 20 of 75
How long will this code take if each request lasts 1 second?
for (const id of [1, 2, 3]) {
await fetchUser(id);
}- ✓Correct answer: ~3 seconds: the requests run sequentially
- 2~1 second:
for...ofruns them in parallel - 3Instantly:
awaitinside a loop is ignored
Explanation
Each await waits for completion before the next iteration. If the requests are independent, run them in parallel: await Promise.all(ids.map(fetchUser)) - about 1 second. Sequential order is needed when the next step depends on the previous one.