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 trialTony Shangkuan
7,200 PointsIs there any practical scenario that we would not want to declare an object using "let"?
I see the video using const
when declaring the object, but I don't quite understand why const
but not let
?
1 Answer
Danny L.
10,837 PointsA few different reasons:
- const if the variable wonβt change (constant), let if it will
- helps readability, others reading your code know when a variable is constant vs when it might change
- Helps prevent you from mistakenly reassigning a variable in other parts of your code
- It becomes more necessary when using TypeScript as well