Question 4
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
async function loadAll(ids) {
return ids.map((id) => await fetchUser(id));
}
- A It returns the users
- B SyntaxError: await is only valid inside an async function, and the arrow callback is not async – use async (id) => … with Promise.all Correct
- C It returns an array of promises
- D ReferenceError: fetchUser is not defined
Correct Answer: Option B
Being inside an async function is not enough; the await belongs to the arrow function. Write return Promise.all(ids.map(async (id) => fetchUser(id))) – or simply ids.map(fetchUser).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!