<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?
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 **
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.