Question 6
Back to Exercise
Callbacks created in for (var i = 0; i < 3; i++) all print 3. What is the simplest fix?
- A Use setTimeout with a delay of 0
- B Declare the loop variable with let Correct
- C Use an arrow function instead of a regular function
- D Declare i with const outside the loop
Correct Answer: Option B
let gives each iteration its own binding. Arrow functions change this, not scope; const would fail on i++.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!