Temporary dead zone

What is a temporary dead zone?

Temporal dead zone

The simple understanding is that you cannot use this variable before the variable declaration, which is equivalent to just starting school and you have come to a new group, although you know that there are XXX students in your class,

But if you don't know them, you can't just find a classmate and say: "Hello, XXX classmate". (I am afraid you are here to be funny!!! Hahaha)

This means you can’t just call someone’s name unless you know him 

The same is that you cannot use the variable before the variable is declared

Book explanation:

        When the javascript engine scans the code and finds the variable declaration,

        (1) Either promote them to the top of the scope, for example: variables declared by var,

        (2) Either put the declaration in TDZ, for example: let and const declaration

        (3) Only after the variable declaration statement is executed, the variable will be removed from the TDZ, and then can be accessed normally

My understanding:

        (1) When accessing the variables declared by let and const, if the access location is before the declaration, the access will fail.

LZ little knowledge:

         (1) Functions have two scopes: one is parameter scope, the other is function body scope

                 I think I should pay attention to this in my daily study. I think it is necessary to know this and I hope it can help you

 

   

Guess you like

Origin blog.csdn.net/L_Z_jay/article/details/112991160