Before ES6 (2015), JavaScript had only Global Scope and Function Scope.

ES6 introduced two important new JavaScript keywords: let and const.

These two keywords provide Block Scope in JavaScript.

Variables declared inside a { } block cannot be accessed from outside the block:

Block Scope and shadowing in JS

https://www.youtube.com/watch?v=lW_erSjyMeM&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=10&ab_channel=AkshaySaini

Example:

// single statement 
if(true) true 

// multiple statement with block 
if(true) {
	// statement 1 
	// statement 2 
	// statement 3
}

{
var a = 10;
let b  = 100;
const c  = 1000;
}

Shadowing in JavaScript

var a = 100;
{
var a = 10;
let b  = 100;
const c  = 1000;
console.log(a);

}
console.log(a);

// output 
10
100 

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0cb059e8-a7c6-448e-a0fa-16717a3605a8/Screenshot_2021-07-24_121718.jpg