What’s the difference between using let and var to declare a variable in ES6?

Technology CommunityCategory: JavaScriptWhat’s the difference between using let and var to declare a variable in ES6?
VietMX Staff asked 3 years ago

The difference is scopingvar is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block. Also, variables declared with let are not accessible before they are declared in their enclosing block. This will throw a ReferenceError exception.