A lexical variable was accessed before it was initialized. This happens within any block statement, when variables declared with let
or const
are accessed before the place where they are declared has been executed.
Note that it is the execution order of access and variable declaration that matters, not the order in which the statements appear in the code. For more information, see the description of Temporal Dead Zone.
This issue does not occur for variables declared using var
, because they are initialized with a default value of undefined
when they are hoisted.
This error can also occur in cyclic imports when a module uses a variable that depends on the module itself being evaluated.