Alright, so const and let was introduced in ES6. I have covered each of them in detail on my blog here.
In short, var is a way of setting the variables in JavaScript; however, the problem is the fact that JavaScript has something called Variable Hoisting. What it means is that the variable is scoped outside the base scope. It sounds really confusing, but what it really means is:
x = 10;
console.log( x );
var x;
will be converted to, on interpretation:
var x;
x = 10;
console.log( x );
Now, generally this is good, but it poses a problem when you use the variable with the same name in different scopes. Take the following example:
function someFunction() {
var myVariable = 10;
if( true ) {
var myVariable = 20;
console.log( "Value inside the block: " + myVariable );
}
console.log( "Value outside the block: " + myVariable );
}
someFunction();
The value, in both the cases, will be 20. However, with const and let, the value of myVariable within the if-scope will be 20, but outside that, it'll be 10.
You use let for general variables, and const for constants. Both have block-level scoping! :D
In the post, I mention again, I have covered this and all the new, cool features of ES6 extensively with examples; be sure to check it out! :)
I hope this helps!