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 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
215,356 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 88,537 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!