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
Kent Hefley
11,217 PointsWhy "Let", "Const" and not "Var"
My question is based in the fact that I don't quite understand their differences. The intro to Javascript courses with Dave McFarland use "var" in each example. Why is "var" not used in this project course
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Kent,
let and const are newer keywords that you can use to declare variables in javascript. You didn't specify which course you're on but I would guess that you're on a newer course as opposed to the older courses you mentioned which would be using the var keyword.
One of the benefits of let and const is that it gives you block level scope for variables. So in other words, a variable declared with those keywords inside a loop, would only exist inside the loop.
With the var keyword, variables either exist for an entire function, if declared inside a function, or they exist in global scope if not declared within any function.
The following workshop explains these newer keywords: https://teamtreehouse.com/library/defining-variables-with-let-and-const
Kent Hefley
11,217 PointsKent Hefley
11,217 PointsThank you Jason. You are right. I am taking the Javascript and the Dom course. I will watch the workshop you suggested.