Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
How do block scopes have access to enclosing scope

i do understand that due to lexical scoping, block scopes can access the enclosing scope variables. But what i do not understand is how it really works. ex:

function first(){
  let i=10;
  function second(){
    let j=20;
    console.log(i);
    if(j==20){
    console.log(i);
  } 
  }
  second();
}

the first console.log() get the value of i after its looks up the scope chain in the variable object. But how does the console.log() inside the block get access to variable i as it does not create an execution context and thus no scope chain.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

js engine stores hoisted ( by hoisting ) variable and function declarations to the top of particular scope in which that variable or function is declared. Assignment operations aren't hoisted. So engine knows in which scope variable or function is declared.

https://medium.com/@venomnert/how-js-engine-reads-your-code-df3cd36e4192

above article describes how js engine finds variables and some other concepts which can be helpful to understand closures and execution of code.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda