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

Dave Harrison
seal-mask
.a{fill-rule:evenodd;}techdegree
Dave Harrison
Front End Web Development Techdegree Student 7,400 Points

Use of Const & Let

I am not sure I have got my head completely around the differences between Const and Let and when to use them. In the example in this video, why did Const get used in the text.Content example and Let in the inner.HTML example?

2 Answers

Hanna Mchatton
Hanna Mchatton
10,279 Points

Use let for a variable that will be changing (array, numbers, inputs values). Then use const for variables that remain unchanged. (a predefined static number, a static name, some elements of the dom). The real difference between them is once you assign "bind" a value to a const you can't change it. When you use let you can reassign the variable with a new value.

In the video, Guil is using const for dom elements that stay static. Then uses let for dom elements that do not. The length of the <ul> is growing and shrinking so the value is constantly changing. The <p> is only a container so the value does not change only the content.