if we will declare a let inside function then we cant access that outside of the fucntion .
let keyword have a scope of block level where the var keyword have a function level scope.
difference between var and let lies in their scope i.e var scope lies to the nearest of function block and let scope lies to the nearest of enclosing blockExample:function demoVarAndLet() {// var variable scopefor (var i = 0; i < 5; i++) {}if (typeof i === 'undefined') {console.log('i(var) is undefiend and not accessible after the loop')} else {console.log('i is accessible after for loop i:' + i + ' type: var ');}for (let j = 0; j < 5; j++) {// let variable scope}if (typeof j === 'undefined') {console.log('j(let) is undefiend and not accessible after the loop');} else {console.log('j is accessible after for loop i:' + i + ' type: let')} }For Live Demo: https://jsfiddle.net/rehmanshahid/3Lnyzd49/
The var keyword is called function-scoped while let is block-scoped variables.
When JavaScript reads your variable declarations that uses the var are lifted to the top of local scope (if declared inside a function). Otherwise lifted to the top of the global scope (if declared outside a function).
Lastly, let are accessible inside the block to where it was defined.