Do you know what will be the output of this code?
JavaScript
for (var i = 0; i < 3; i++) {}
console.log(i);
Show answer and explanation
The answer is 3.
var is scoped to the function (or the global scope), not the loop block. The loop stops when i < 3 is false, which is when i is 3.
With let i, the variable would only exist inside the loop and this would throw a ReferenceError.