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

Startup Shell
Startup Shell
37,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?


Michal Janek
Michal Janek
Front End Web Development Techdegree Graduate 30,651 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.

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: