The difference between "alert (a)" and "alert" (a): var a = 1; '' in javascript?
<script type="text/javascript"> alert(a); </script> The console log shows: "Unused ReferenceError: a not defined";
<script type="text/javascript"> alert(a); var a = 1; </script> in the middle of viewing, the log shows: "undefined"
How does this code work in js and what makes this difference
in this code
<script type="text/javascript"> alert(a); var a = 1; </script> var a ; rises up and becomes
<script type="text/javascript"> var a; alert(a); a = 1; </script> therefore, at the time of a it was warned that it was undefined
In this code
<script type="text/javascript"> alert(a); </script> a was not defined at all, so it gave the error "Uncaught ReferenceError: a is not defined"