Bummer! This is just a preview. You need to be signed in with an account to view the entire instruction.
- Introducing Loops, Arrays and Objects 1:29
- Before You Start With Loops
- What are Loops? 7:52
- Review Loops 5 questions
- Complete the Loop 1 objective
- Create a while Loop 1 objective
- A Closer Look at Loop Conditions 8:06
- A Closer Look At Loop Conditions 1 objective
- `do ... while` Loops 6:57
- Review while loops, do...while loops, and Loop Conditions 5 questions
- Create a `do...while` loop 1 objective
- For Loops 7:21
- Create a for Loop 1 objective
- Exiting Loops 4:05
- Review For Loops and Loop Exiting 6 questions
- Using let with for Loops
- The Refactor Challenge 2:52
- The Refactor Challenge Solution 2:22
- The Refactor Challenge, Part 2 4:16
- Refactor Using a Loop 1 objective
Well done!
You have completed JavaScript Loops, Arrays and Objects!
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 complete, the value of i is...