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 trialAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsUsing let with for loop
I have a doubt here with const .
If the value of button is changing after every iteration i,e button 0 , button 1 , then why he used const to declare button ?
3 Answers
Steven Parker
231,059 PointsIn this video, "button" is assigned inside a loop. Before the loop repeats, "button" is disposed (no longer exists).
On the next iteration, a new "button" is created. The old one is not being re-assigned.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsOh . Thanks
I just got confused with the word "const" , I forgot that the value gets stored in stack . And it also vanished into next repitition.
Thanks again .
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsIn the previous case , the variable status was a part of login_info object.
But here it's a seperate variable.
And if it's the only property of the button that is changing , then how will it be reassigned so that we will get a Uncaugh type error .
Please help me with example.
I am sorry . I am still confused.
Steven Parker
231,059 PointsSteven Parker
231,059 PointsEach iteration has a different context. So this:
Is essentially the same thing as this:
In both cases, the constant(s) exist only between the braces.