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

164
Visualizações
block scope influencing declarations outside of it

<p id="Test1"></p>
<p id="Test2"></p>
<p id="Test3"></p>

<script>
    {
        let v;
        v = 10;
    }

    let g = 20;

    var h = 15;

    document.getElementById('Test1').innerHTML = v;
    document.getElementById('Test2').innerHTML = g;
    document.getElementById('Test3').innerHTML = h;
</script>

As far as I learned, the let declared variables, can't be used outside a blocked scope, but if I run the code above, none of the 3 get shown? why is that? the scope ended there right?

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

0

When an error occurs, JavaScript will normally stop and generate an error message. The technical term for this is: JavaScript will throw an exception (throw an error). JavaScript will actually create an Error object with two properties: name and message. **SO HERE AS SOON AS COMPILER TRY TO SHOW "v" js compiler throw error **

  • Uncaught ReferenceError: v is not defined And it terminate execution due to which you can not see that value of g and , h. here are two case: ** case 1** AS "v" IS COMMENTED YOU CAN SEE VALUE OF g and h(without error in console).
    let g = 20;
    
    var h = 15; {
    
      let v;
      v = 10;
    }
    
    
    //document.getElementById('Test1').innerHTML = v;
    document.getElementById('Test2').innerHTML = g;
    document.getElementById('Test3').innerHTML = h;
    <p id="Test1"></p>
    <p id="Test2"></p>
    <p id="Test3"></p>

** CASE 2** ** I TRIED TO ACCESS v VALUE AS LAST SO NOW YOU CAN SEE VALUE OF g and h as IT WAS EXECUTED EARLIER BEFORE THE ERROR THROWN BY COMPILER.

let g = 20;

var h = 15; {

  let v;
  v = 10;
}



document.getElementById('Test2').innerHTML = g;
document.getElementById('Test3').innerHTML = h;
document.getElementById('Test1').innerHTML = v;
<p id="Test1"></p>
<p id="Test2"></p>
<p id="Test3"></p>

JavaScript is a single-threaded language, where only one command executes at a time. It has a Synchronous model of execution, where each line is executed line by line, top to bottom.

UNIT AND NLESS THERE IS COME FUNCTION SUCH AS SET TIMEOUT OR ASYNCHRONIZED FUNCTION. WHICH EXECUES DIFFERENTLY.

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