A. Using forEach with async does not wait for all fetches to finish.
B. Missing JSON.stringify on fetch body.
C. results array is declared inside the loop.
D. fetch should not be awaited inside async function.
Solution
Step 1: Analyze async inside forEach
forEach does not wait for async callbacks, so results may be empty on return.
Step 2: Identify correct fix
Use for...of loop with await or Promise.all to wait for all fetches.
Final Answer:
Using forEach with async does not wait for all fetches to finish. -> Option A
Quick Check:
forEach async does not await = Using forEach with async does not wait for all fetches to finish. [OK]
Hint: Avoid async inside forEach; use for...of or Promise.all [OK]
Common Mistakes:
Assuming forEach waits for async callbacks
Not returning or awaiting promises properly
Misplacing results array declaration
5. You want to send 100 API requests in batches of 10 asynchronously to avoid overloading the server. Which approach correctly implements this in JavaScript?
hard
A. Send requests one by one using a for loop with await inside.
B. Send all 100 requests at once with Promise.all without batching.
C. Use a forEach loop with async fetch calls without awaiting.
D. Split URLs into chunks of 10, then use Promise.all on each chunk sequentially.
Solution
Step 1: Understand batch size control
Sending all 100 requests at once may overload the server; batching limits concurrency.
Step 2: Implement batch processing
Split URLs into groups of 10, then await Promise.all for each batch sequentially.
Final Answer:
Split URLs into chunks of 10, then use Promise.all on each chunk sequentially. -> Option D
Quick Check:
Batch requests in chunks with Promise.all = Split URLs into chunks of 10, then use Promise.all on each chunk sequentially. [OK]
Hint: Batch requests in small groups, await each batch [OK]
Common Mistakes:
Sending all requests at once causing overload
Not awaiting async calls properly
Sending requests one by one losing async benefits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.