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 trialLucas Santos
19,315 PointsWhy 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
56,413 PointsIf you keep watching you'll see it's JSX. He's just defining it as empty for the moment.
Christian Tucker
Courses Plus Student 1,987 PointsKeep 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.
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsI'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
56,413 PointsSeth Kroger
56,413 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
19,315 PointsLucas Santos
19,315 PointsGot it thanks Seth!