Just to add clarity - The compiler executes the script in 2 phases. In the first one it allocates and defines all variables it finds including var, let and even const. In the 2nd phase it runs the code line by line thereby giving a feeling that declarations were moved to top. There is no such script alteration at runtime.
Just to add clarity - The compiler executes the script in 2 phases. In the first one it allocates and defines all variables it finds including
var
,let
and evenconst
. In the 2nd phase it runs the code line by line thereby giving a feeling that declarations were moved to top. There is no such script alteration at runtime.Yes, well said! Thank you for this.