Startup Shell37,339 Points
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?
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