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 Router Basics Navigating and Nesting Routes Organizing Your Routes

Lucas Santos
Lucas Santos
19,315 Points

Why is he defining an object with parenthesis and not the curl brackets?

On 1:27 of this video he says,

"So, I'll create a routes object by typing const routes."

then created an like so,

const routes = ();

would it not be like this,

const routes = {};

is this an ES6 way of defining objets or JSX? I'm not 100% sure.

2 Answers

Seth Kroger
Seth Kroger
56,405 Points

If you keep watching you'll see it's JSX. He's just defining it as empty for the moment.

Lucas Santos
Lucas Santos
19,315 Points

I'm aware that it's not going to be empty, I just defined it with nothing inside so you can see what i'm talking about.

Ok so that means that {} is not how you define an object when using JSX but instead it's parenthesis.

Seth Kroger
Seth Kroger
56,405 Points

{} is always how you define an object. JSX uses () for the inclusion of HTML/XML components. Since the Router and Routes are React components we're defining them in XML, hence the ().

Lucas Santos
Lucas Santos
19,315 Points

Got it thanks Seth!

Christian Tucker
PLUS
Christian Tucker
Courses Plus Student 1,987 Points

Keep in mind that () is not required, you can just as easily do

return <Router ...>
    ...
</Router >;

Which seems more legible to me. He switches between the two styles it seems.