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 trialLoris Yu
6,294 PointsWhy we need to "const name = req.cookies.username" twice in different "get" requests?
Why we need to "const name = req.cookies.username" twice in different "get" requests?
2 Answers
Sheila Anguiano
Full Stack JavaScript Techdegree Graduate 35,239 PointsWe need it, because two things:
- The scope of the const is LOCAL therefore the variable name only exist within each function
- A constant is defined as something that won't change so if you create the variable in the GLOBAL scope it cannot be changed from having a string (input name) and not having one (delete your name from the app). Also it makes it more readable and modular, thus easy to debug
Hope this helps
Loris Yu
6,294 PointsThank you!