variables declared using let and const are also hoisted but only difference is that in case of let/const , variables are not initialized with undefined as in case of var/function.
x=10;console.log(x);letx=20;
above code will throw reference error as variable x in temporal dead zone . If it was not hoisted then x would have been 10.
Basically for let and const TDZ start with commencing of the block inside which particular variable is declared and initialized and it will exit TDZ when js interpreter/executor reach that line.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
variables declared using let and const are also hoisted but only difference is that in case of let/const , variables are not initialized with undefined as in case of var/function.
above code will throw reference error as variable x in temporal dead zone . If it was not hoisted then x would have been 10.
Yes you are correct indeed. I've fixed my error. Thank You for pointing this major blunder out!
Basically for let and const TDZ start with commencing of the block inside which particular variable is declared and initialized and it will exit TDZ when js interpreter/executor reach that line.