Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
12,932 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.