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

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction Listening for Events with addEventListener()

Difference Between let and var

I'm just trying to get a better understanding of JS in general. In this video we use a for loop to apply the handler to each li element. While I did this I didn't follow the video exactly and used var in my for loop instead of let. When I used var the program didn't run properly but using let allowed it to work fine.

Is there any reason for this?

Thanks,

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

There has been a change on defining variable with the word var. I do believe it has changed into: const / let

each having their specific usage. There is a workshop with Andrew on this issue. https://teamtreehouse.com/library/defining-variables-with-let-and-const

1 Answer

JavaScript, like most languages is sometimes revised and reworked to add new features, abilities, etc. ES6, a/k/a ECMAScript 6 is the latest JS standard.

The latest ES6 standard introduced new identifiers, let and const. Let is very similar to var in the way that it lets you update or reassign it. For example, if you had a (let foo = 'foo') and wanted to later update it, you would just do (foo = 'oof') however, with const, it's constant and cannot be changed, it is however immutable which means whilst you cant just change any existing properties (confirmation needed) you're able ADD new properties.

There's an awesome blog writeup for it here: http://blog.teamtreehouse.com/get-started-ecmascript-6