//let
1. It's used in block-scoped.
2. It does not allow to redeclare variables.
3. Hoisting does not occur in let.
// var
1. It's used in function scoped.
2. It allows to redeclare variables.
3. Hoisting occurs in var.
let: //only available inside the scope it's declared, like in "for" loop,
var: //accessed outside the loop "for"
let = 10 // accessable only in defined scope
var = 10 // accessable in the function it is declared in (global variable in a function)
/* DIFFERENCE BETWEEN LET AND VAR */
//LET EXAMPLE
{
let a = 123;
};
console.log(a); // undefined
//VAR EXAMPLE
{
var a = 123;
};
console.log(a); // 123
var makes a grobal variable
let makes a local variable