Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda