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 and the DOM (Retiring) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

Nicholas Wallen
Nicholas Wallen
12,278 Points

Why did he use const for the variables here, when the last video he used let.

Please do not refer me to the Const and Let Workshop Video, I've watched it multiple times, and it doesn't answer this question.

Two videos, he declared variables which were basically the same. This video he chose const, last one, he chose let. Is there a reason why?

1 Answer

Steven Parker
Steven Parker
231,269 Points

The general "best practice" is to use "const" for any variable that will not change during it's scope lifetime. If it needs to be changed in the program, use "let" instead.

Using "let" for things that don't change will not cause any problems, it just doesn't take advantage of the "const" protection. You can't change anything defined with "const", you'll get an error if you try.