Block Scope
Block Scope
Before ES6 (2015), JavaScript variables had only Global Scope and Function
Scope.
ES6 introduced two important new JavaScript keywords: let and const.
Example
let x = 2;
Variables declared with the var keyword can NOT have block scope.
Variables declared inside a { } block can be accessed from outside the block.
Example
var x = 2;
}
Local Scope
Example
function myFunction() {