Hi makenzi.exc,
var: Declares variables with function or global scope and allows re-declaration and updates within the same scope.
let: Declares variables with block scope, allowing updates but not re-declaration within the same block.
const: Declares block-scoped variables that cannot be reassigned after their initial assignment.
var and let create variables that can be reassigned another value.
const creates constant variables that cannot be reassigned another value.
So we shouldn't use var anymore and use let or const instead.
<script type="text/javascript">
var x = 1;
if (true) {
var x = 2;
alert(x);
}
alert(x);
</script>
<script type="text/javascript">
let x = 1;
if (true) {
let x = 2;
alert(x);
}
alert(x);
const i = 0;
alert(i);
</script>