Let is block level scope local variable and const is same as let but read-only single assignment variable.
var obj = {
name: 'Gokul',
age: 21,
car: 'Swift'
};
//let is block level variable here
for (let i in obj) {
console.log(i); //print name age car
}
console.log(i); //i is not defined
let
will also throw an error if any duplicate declaration is made
if (true) {
let foo = 10;
let foo = 11; //Duplicate declaration "foo"
}
console.log(foo); //foo is not defined
const bar = 'Hello';
console.log(bar); //print Hello
bar = 'World'; //"bar" is read-only