Why the extra parenthesis?

Tell us what’s happening:
So I have the correct solution(i found it in the solutions tab) and my solution was basically correct but it didnt have the extra parenthesis after the arrow in the arrow function. my question is why are these needed? in the example code:
const names = users.map(user => user.name);
the parenthesis are not there and instead theres only one set of parenthesis after .map. is it because its on multiple lines? or maybe because the function is more complicated?

Your code so far

var ratings = watchList.map(movie => ({
    "title": movie["Title"],
    "rating": movie["imdbRating"]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Challenge: Use the map Method to Extract Data from an Array

Link to the challenge:

If you have {}, the arrow function is expecting a function body with an explicit return statement. This is inconvenient when we want to return an object. So you wrap the object literal in () to let JS know that you are returning an object literal rather than putting a function body between the {}s.


Often, when you have questions like this, it’s likely a point of confusion for others. Part of freecodecamp’s Read-Research-ask is searching past posts on this very forum:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.