Skip to content

Spot the Off-by-One Error

Find the Mistake Easy
workbench

Question

This loop is supposed to print all elements of a 3-element array but skips the last one. What is wrong?

Code

                  const arr = [10, 20, 30];
for (let i = 0; i < arr.length - 1; i++) {
  console.log(arr[i]);
}
                

Related Resources

Related Lessons

  • Loops

    Learn about loop boundaries.

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

← Back to topic