I was going through Lexical environment and environment record / scope in JS.
I know difference (partly) between var and let (one being block scoped, while one being functional scope) and also the let being in TDZ before being assigned any variable.
I executed the following piece of code but now I am little bit confused.
Confusion : In global code, var a is assigned to GLOBAL scope because its a var, while let b is being hoisted in a separate memory space (Here being the Script Scope). So we cannot access it before being initialized (TDZ).
But same concept when I am writing it in the function, we only have one scope which is the Local Scope of that function, then how is JS knowing the difference between a1 and b1 ? When I am running debugger both are setting to undefined (in creation phase) and both are being set to 1 during their execution phase. Like we are not having two different scope unlike a and b right ?
Also can some explain what is Script in Scope (or atleast give any reference for it where I can see it)