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 trialMagdalena Frankowska
15,501 PointsLet And Const
During the video we are using const, but in the challenge we use let - what's the difference if we're basically doing the same thing in the video as in the challenge ?
1 Answer
Steven Parker
231,248 PointsWhile the language does not require you to do this, it is considered a "best practice" to use "const" for defining anything that will not change later in the program.
But if the variable will be re-assigned later, you must use "let" (or "var").
The fact that "let" was used in the challenge implies that more code might be added later that would re-assign that variable. But since that does not happen in the challenge tasks, you can use "const" instead of "let" if you want without affecting the outcome.
eslam said
Courses Plus Student 6,734 Pointseslam said
Courses Plus Student 6,734 PointsYou can't reassign a const, use const when you want a value to be fixed
const price = 10;
if you try to reassign price you will get an error