Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Displaying the Content

Why does not .map work when I use curly braces in the call back?

When I use curly braces in the callback function within the .map method no list is shown. When these are removed however, it seems to be working. How come?

This does'nt work, function generateOptions(data) { const options = data.map( item => { <option value='${item}'>'${item}'</option> }) select.innerHTML = options; }

This does. function generateOptions(data) { const options = data.map( item => <option value='${item}'>'${item}'</option> ) select.innerHTML = options; }

2 Answers

Blake Larson
Blake Larson
13,014 Points

When the only statement in an arrow function is return, we can remove return and remove the surrounding curly brackets. If you have the curly braces you need to have a return.

Thank you Blake for this. Should be marked as the best answer.