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

Anthony Candaele
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Candaele
Full Stack JavaScript Techdegree Student 32,135 Points

I'm not sure if i fully understand this syntax: const { side } = req.query;

I believe this is called 'destructuring' but I am not sure what the part 'const { side } does, why is between brackets?

2 Answers

Steven Parker
Steven Parker
229,732 Points

You're exactly right, this is a destructuring assignment. The brackets indicate an object (the "structure") that "side" will be found inside of. So we can expect that the "req" object contains another object named "query" which will have a property named "side". The value associated with that property will be assigned to the new constant named "side".

Steven Parker
Steven Parker
229,732 Points

Essentially, yes, but not as easy to read. I'd code it your way. :wink: