Pergunta comum em entrevista de JavaScript. A resposta abaixo está em inglês, do jeito que dá para falar numa entrevista: leia, feche e tente explicar com as suas palavras.
Hoisting describes observable behavior from how JavaScript creates and initializes bindings. The engine does not move source lines.
Function declarations are initialized with their function value before the scope's statements run. var bindings are initialized to undefined, but their assignments run where written. let, const, and class bindings remain uninitialized until their declaration is evaluated. Access during that Temporal Dead Zone (TDZ) throws ReferenceError, even if an outer binding has the same name.
Example: reading a var before its assignment gives undefined. Calling a function expression assigned to that var at that point throws TypeError because undefined is not callable. Reading a let before initialization throws ReferenceError.
A function written before let x can read x when called after x is initialized. Execution order determines whether the access is in the TDZ.
Source: MDN hoisting.
Ler é o primeiro passo. No app, essa pergunta vira flashcard com repetição espaçada, e o módulo tem quiz e simulado para testar o que ficou.
Treinar essa pergunta no app