Predict the Error Type
Predict Output Medium
Question
What type of error does this code produce?
Code
let arr = [1, 2, 3];
console.log(arr[10].toString());
Hint
arr[10] is undefined because the array only has 3 elements.
Explanation
arr[10] is undefined (the array only has indices 0-2). Calling .toString() on undefined throws a TypeError. This is a runtime error — the code is syntactically valid and starts running, but fails during execution when it tries to access a property of undefined.
Related Resources
Related Lessons
- Errors
Learn about common programming errors.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.