Reading error messages
You'll learn to read a JavaScript error message, find the line it points to, and ask AI for help with the right details.
Watch & read
Start with the required ones. The others are there when you need them.
Explanation
Your code stops and the console turns red. It is tempting to panic or paste it straight into AI. Instead, read it. An error message tells you what went wrong and where.
Every message has the same shape:
Uncaught TypeError: Cannot read properties of undefined (reading 'name')at nameAt (app.js:4:26)at app.js:8:13
The first word is the type of error. Then comes the message in plain English. The lines that start
with at are called the stack: the path the code took to get there. The first at line is where it
broke: file app.js, line 4, character 26. The next line shows who called it.
Three types cover most beginner errors:
- ReferenceError: x is not defined. You used a name that doesn't exist here. Check the spelling, and check scope.
- TypeError: Cannot read properties of undefined (reading 'name'). You wrote
something.name, butsomethingwasundefined. The problem is the thing before the dot. Often afindfound nothing, or an index was past the end of an array. - SyntaxError. The code is not valid JavaScript, like a missing
)or}. Nothing runs at all. Look at the line it names, and also the line just before it.
People often read only the first few words and then guess. Read the whole first line, open the file at that line number, and ask: which value here is not what I expected?
When you ask AI, give it three things: the full error message, the few lines around the line number, and what you expected to happen. "Fix my code" gets a guess. Those three things get a real answer, and you learn why.
Code tour
Click a line number with a ring to read the note for that line.
Practice
Short drills. Take your time and read the code before you answer.
1const price = 100;2console.log(prise * 2);
label should be the first letter of the last student's name, in capitals: "N". Fix it so both checks pass.Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3You see
ReferenceError: totl is not defined. What is the most likely cause? - 2 / 3
user.namegivesCannot read properties of undefined (reading 'name'). What was undefined? - 3 / 3In
at checkout (cart.js:12:9), where do you look first?