How javascript run Internally

How javascript run Internally

global scope and block scope

Block level Scope : variable declared inside a {} block, it can not access from outside the block is called block Scope.

ES6 introduced block scope two keywords that is let and const.

{ 
   let x = 2;
}
// x can not be acces from here

Global Level Scope : variable declared Golobally (outside any function ) have global scope . and all bellow function can acces it. variable var is global scope variable

let mobileName = "redmi";
// code here can use carName

function myFunction() {
// code here can also use mobileName
}

How javascript code work intrnally =>

javscript : javscript read the code line by line and then execute the code

when javaacript read the variable VAR go to global scope and other (let , const ) variable go to block scope.

console.log(a);
var a =10;
console.log(a);

when the scan was done, first console.log(a) will be able to read variable a because variable a is globally available and it will show a= undifiened .

console.log(a);
let a = 10;
console.log(a);
// bellow wxplaination

when system scanned whole code . and then system knowing i have variable a .But is not present in global is kept some where hiddin (Ex. script block) .This is caled as Temporal Dead zone. beacuse of this code show a error.