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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![gene c](https://uploads.teamtreehouse.com/production/profile-photos/9482412/micro_Shanghai_Skyline_Lightroom.jpg)
gene c
13,630 PointsSo do I use "var" or "let" to declare variables now?
In a previous video in the same track, I was taught to avoid using "var" to declare variables as "var" had some scope issues.
Now this video is using "var" to declare variables. So I am confused.
6 Answers
![Daniel Rivers](https://secure.gravatar.com/avatar/04e71b4645058d449447432c9c577f4b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Daniel Rivers
2,931 PointsI generally start with const by default now, but decision between var and let is really about scope, I often use lets inside a loop or a function where the scope is only to that part of the code.
If I need more global scope and a changing variable I will use var.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsIf you need function scope or hoisting, you'd need "var". But if you rethink your code structure, you can probably change it so neither of these is required. And I personally like using "var" for global variables to visually distinguish them.
Otherwise, using "const" for things that do not change, and "let" for things that do are good practice choices.
![Alexander Davison](https://uploads.teamtreehouse.com/production/profile-photos/4157542/micro_binary.jpg)
Alexander Davison
65,469 PointsAgreed
![tomd](https://secure.gravatar.com/avatar/c16dbf84d90c244d3bbd70fc7aa3ffeb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
tomd
16,701 PointsYou should use 'const'. Unless you need to change the value of a variable later on, then use 'let'.
'Var' is still being used in TreeHouse videos because the videos are old. But they are still relevant.
![Daniel Vazquez](https://secure.gravatar.com/avatar/2b2d3b64e583533ff084cac080cb487d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Daniel Vazquez
Courses Plus Student 7,905 PointsAs I understood, var should be always be avoided from now on...
- const should be your first option, and if you don't want your variable to be overwritten later on.
- let is for when te value of your variable is going to be overwritten altogether.
![Kevin Gates](https://secure.gravatar.com/avatar/e6d902128dd45e6d463bc4f42dee5fcd?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Kevin Gates
15,053 PointsTo quote Pirates of the Caribbean, "They're more like guidelines than actual rules."
Be wise, but ultimately use the best tools for the job. Remember, at the end of the day, "Done is better than perfect."
![farouq siwoku](https://secure.gravatar.com/avatar/720140c0151cf4d4e496c6cd292b6d5e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
farouq siwoku
Full Stack JavaScript Techdegree Student 7,324 PointsYou should always use let when you can i.e use it more often. while var has issues with scope and its generally not in use anymore. You should also use const to declare variables cause it helps to prevent errors.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI think of "const" and "let" as additional (though commonly used) tools in the toolbox, but not replacements.
There are still reasons to use var; it provides function scope and hoisting, the others don't do either. Also, if you use sandbox tools like "codepen", you might find that things declared in the console with "var" work as expected, but you may have problems accessing things declared with "let" or "const".
Daniel Rivers
2,931 PointsDaniel Rivers
2,931 PointsI generally start with const by default now, but decision between var and let is really about scope, I often use lets inside a loop or a function where the scope is only to that part of the code.
If I need more global scope and a changing variable I will use var.