If I omit the 'let' or 'var' from a javascript for-loop, it still works. So instead of declaring "let i = 0" in the loop and just typing "i = 0" it still seems to have the same scope and works the same. Why is that?
How can the "i++" part work without knowing what type it is and without knowing its start value?
This code still executes properly:
<p id="demo"></p>
<p id="i"></p>
<script>
const cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"];
let text = "";
let iter = "";
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
iter = i;
}
document.getElementById("demo").innerHTML = text;
document.getElementById("i").innerHTML = iter;
</script>```