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
Jack Camp
6,121 PointsUsing 'var' over 'let'
I just learned what the let keyword is and am struggling to find any sort of difference between it and the standard 'var' keyword. Any clarification would be great :)
1 Answer
Steven Parker
243,656 PointsThe more modern and recommended term is "let", but I can think of three differences that might be reasons to use "var":
- anything declared with "var" has function (or global) scope instead of block scope
- a "var" declaration is hoisted
- when used for globals, "var" creates a property on the global object
The need for these can be mitigated with thoughtful program design, but I still like to use "var" for globals to help make them more distinctive at first glance.