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

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
220,925 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
220,925 Points

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