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 React by Example Building the Application Writing a Handler to Confirm Guests

return() and return{}

In the video at say 7:00. The return inside the map uses {}. which as far as I understand will returns a new object since objects are inside {}. But what does return() stands for? Anything can be returned inside ()? An array, string, func or an object? Thank you.

2 Answers

Steven Parker
Steven Parker
229,645 Points

Since "return" is a statement keyword and not a function, it does not need parentheses. If you use some anyway, they are interpreted as a grouping operator and part of the following expression.

And yes, most any kind of thing can be returned.

Torben Korb
.a{fill-rule:evenodd;}techdegree seal-36
Torben Korb
Front End Web Development Techdegree Graduate 91,390 Points

Using parentheses when returning is necessary if you want to write your return statement over several lines (from https://stackoverflow.com/questions/20824558/why-use-parentheses-when-returning-in-javascript).

Returning several lines is something you can see commonly in React when returning component code. Happy coding!