ES(ECMASCRIPT) 6 provides two new ways of declaring variables: let and const, which mostly replace the ES5 way of declaring variables, var.
LET
let works similarly to var, but the variable it declares is block-scoped, it only exists within the current block. var is function-scoped.
function order(x, y) {
if (x > y) { // (A)
let tmp = x;
x = y;
y = tmp;
}
console.log(tmp===x); // ReferenceError: tmp is not defined
return [x, y];
}
CONST
const works like let, but the variable you declare must be immediately initialized, with a value that can’t be changed afterwards.
const allows you to declare a single assignment variable lexically bound.
const foo;
// SyntaxError: missing = in const declaration
const bar = 123;
bar = 456;
// TypeError: `bar` is read-only
VAR
With const and let, there is no more space for var anymore.
Video Tutorial
https://www.youtube.com/watch?v=zfCATpShE5g