In simple words, let is the new var, you use it for variable values. Let and Const are all to changing something behind the scenes about the scope of variables. But the most important takeaway here is to use let if you want to create a variable that really varies (changing values). Use const if you plan on creating a constant value, so something which you only assign once and never changes.
In our upcoming articles, you will never see var, you will only see let and const, and mostly it’s const. So it shouldn’t confuse you, it’s simply the same as var, just in a more modern way, and in the case of const, although clearly showing, this is never going to receive a new value.
We have another JS editor that is JSBIN, an online Web Editor. You can access it from here https://jsbin.com/. When you open JSBIN, the window will look like the following,
Here, we have created a variable ‘myCar’ and assigned a string value to it. And after printing it on the console, we modified myCar to some other string value. Then again we are printing it on the console. So you can run this code by clicking on the “Run” button. And you can see the output. It prints “Alto” in 1st line and “Audi” in 2nd line. Now if we change var to let,
Nothing’s going to change. It still works in the same way. If you use const, Here, it throws an error, since we try to reassign a constant variable. This is const and this is the idea behind const. You can say this should never get a new value and if you accidentally write some code where you reassign it you get the error.