Which fix removes the bug?
for (let i = 0; i <= nums.length; i++) {
console.log(nums[i]);
}
- Change
<=to< - Change
lettovar - Start the loop at
1 - Cache
nums.lengthfirst
Indexes stop at length - 1, so
Play Problem Solving ▸
<= reads one past the end and logs undefined.