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 JavaScript Objects Object Basics Set the Value of Object Properties

Tony Shangkuan
Tony Shangkuan
7,200 Points

Is 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.
Danny L.
10,837 Points

A few different reasons:

  1. const if the variable won’t change (constant), let if it will
  2. helps readability, others reading your code know when a variable is constant vs when it might change
  3. Helps prevent you from mistakenly reassigning a variable in other parts of your code
  4. It becomes more necessary when using TypeScript as well