Bird
0
0

Identify the error in this async batch code:

medium📝 Debug Q6 of 15
Rest API - Batch and Bulk Operations
Identify the error in this async batch code:
async function getData() {
  const data = Promise.all([
    fetch('url1'),
    fetch('url2')
  ]);
  console.log(data);
}
getData();
APromise.all cannot handle fetch requests.
Bfetch calls should be inside a for loop, not Promise.all.
Cconsole.log cannot print Promise objects.
DMissing await before Promise.all, so data is a Promise, not results.
Step-by-Step Solution
Solution:
  1. Step 1: Check Promise.all usage

    Promise.all returns a Promise; without await, data is a Promise, not resolved results.
  2. Step 2: Identify console.log output

    Logging data without await prints a Promise object, not actual data.
  3. Final Answer:

    Missing await before Promise.all, so data is a Promise, not results. -> Option D
  4. Quick Check:

    Always await Promise.all to get results [OK]
Quick Trick: Always await Promise.all to get resolved results [OK]
Common Mistakes:
MISTAKES
  • Forgetting await before Promise.all
  • Thinking Promise.all can't handle fetch
  • Assuming console.log can't print Promises

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes