///////////////***** SCOPES IN JS *************/////////////
let a = 200
if(true){
let a = 100
console.log("inner a is ",a);// 100 (BLOCK SCOPE)
}
console.log("outer a is ",a); // 200 (GLOBAL SCOPE)
/*
BLOCK SCOPE
The space inside the curly braces is called a block space.
variable assigned in block scope only accessable in block scope not in global scope.
Global SCOPE
The space outside the curly braces is called a Global space.
variable assigned in global scope accessable in both block scope and global scope.
*/
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter