JavaScript JavaScript and the DOM 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
177,844 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.