$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #131

Which fix removes the bug?

for (let i = 0; i <= nums.length; i++) {
  console.log(nums[i]);
}
  1. Change <= to <
  2. Change let to var
  3. Start the loop at 1
  4. Cache nums.length first
Indexes stop at length - 1, so <= reads one past the end and logs undefined.
Play Problem Solving ▸