If we use a variable, and this variable is defined later, then the error will not occur. The error will not occur because the compiler already knows all the variables in pass 1. Initial value of variables at pass 1 undefined
That is, it is as if the variables are raised up before they are used.
Html
<html>
<body>
<script>
alert(text1); // see the text "Undefined"
var text1 = "Hello"; // declared a variable text1
</script>
</body>
</html>
Html
<html>
<body>
<script>
// calculate
var c = a * b;
// c = NaN
// declare variables
var a = 5;
var b = 8;
</script>
</body>
</html>
Html
<html>
<body>
<script>
var c = a * b;
// Error! Variables a and b nowhere announced (neither at the beginning nor at the end)
</script>
</body>
</html>