Bummer! This is just a preview. You need to be signed in with an account to view the entire instruction.
Instruction
Using let with for Loops
The let
keyword is especially useful in for
loops. Using var
to define the counter in a for
loop can lead to confusing and unexpected outcomes. For example, consider the following code:
for ( var i = 0; i < 10; i++ ) {
console.log(i); // logs the numbers 0 to 9
}
console.log(i); // 10
The for
loop logs the value of i
to the console ten times. When the loop is ...