Bird
0
0

Identify the issue in this async batch code:

medium📝 Debug Q7 of 15
Rest API - Batch and Bulk Operations
Identify the issue in this async batch code:
async function fetchData() {
  const urls = ['url1', 'url2'];
  const data = urls.map(async url => {
    const response = await fetch(url);
    return response.json();
  });
  console.log(data);
}
fetchData();
AThe console logs an array of unresolved Promises instead of actual data
BThe fetch calls are executed sequentially instead of concurrently
CThe response.json() method is called incorrectly
DThe function fetchData is missing an await keyword before map
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the map with async callback

    urls.map with an async callback returns an array of Promises, not resolved data.
  2. Step 2: Check console.log output

    Logging 'data' immediately shows unresolved Promises, not the awaited JSON results.
  3. Final Answer:

    The console logs an array of unresolved Promises instead of actual data -> Option A
  4. Quick Check:

    Async map returns Promises, must await Promise.all [OK]
Quick Trick: Async map returns Promises; await Promise.all to resolve [OK]
Common Mistakes:
MISTAKES
  • Expecting map with async to return resolved values
  • Not using Promise.all to wait for all Promises
  • Assuming fetch calls run sequentially here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes