tl; dr; quote from section 13.3.1 Let and Const Declarations
It has been established that it has been assessed.
Variables are created when Lexical Environment containing their instances is instantiated, but remain inaccessible in any way before calculating their LexicalBinding.
So, the answer to your question is: yes, let and const float, but you cannot access them, until the actual definition is done at run-time.
As stated above, these variables cannot be accessed before they are declared. However, everything is a little more complicated.
Does this mean that variables declared with let or const do not pop up? What is really going on here?
In JavaScript, all definitions ( var , let , const , function , function* , class ) pop up . This means that if the name is defined in the Osprey, in this Osprey, the identifier will always point to a specific variable:
x = "global"; // функциональный скоп: (function() { x; // не "global" var/let/… x; }()); // блочный скоп (не для `var`): { x; // не "global" let/const/… x; }
This is true both for the functional and for the block Osprey 1 .
The difference between the var / function / function* definitions and the let / const / class definitions in their initialization .
The former are initialized with the value undefined or with a function (generator) right when a binding is created at the beginning of the osprey. However, lexically declared variables remain uninitialized . This means that when trying to access them, a ReferenceError Error exception will be thrown. They are initialized. only at the moment of the execution of the let / const / class expressions, everything before this (above) is called the temporal dead zone .
x = y = "global"; (function() { x; // undefined y; // Reference error: y is not defined var x = "local"; let y = "local"; }());
Notice that the expression let y; initializes the variable to undefined , similar to let y = undefined; .
The temporary dead zone is not a syntactic place, but rather the time between the creation of a variable (osprey) and initialization. So, it will not be an error to access a variable in the code above the definition, until this code is executed (for example, the function body or simply an unreachable code), but an exception is thrown when attempting to access the variable prior to its initialization, even if the access code is below the definition ( for example, in the pop-up definition of a function that was called too early).
Is there any difference between let and const in this case?
No, they work exactly the same if viewed from the ascent. Their only difference is that const ants should and can be assigned only in the initialization part of the definition ( const one = 1; variant const one; followed by assigning the value one = 2 invalid).
1: naturally, the var definition works only at the function level.
Translations of answers @thefourtheye and @Bergi