🔎 What you'll see
Uncaught TypeError: Cannot read properties of undefined (reading 'name')
🤔 Why it happens
A variable has no value yet (it's undefined), but the code tries to read something inside it (like name). It often happens when you use data before it has arrived, misspell a name, or go past the end of an array.
🛠️ How to fix it
- Click the line number in the error to see which variable is undefined.
- Log that variable with console.log right before the failing line.
- If the data comes from a server, make sure you only use it after it arrives (after await, or inside then).
- As a stopgap, optional chaining like obj?.name returns undefined instead of crashing — but still find the real cause.
🤖 What to ask your AI
Replace the parts in [ ] with your own details, then paste it in.
I'm getting this JavaScript error: [full error]. Here's the failing line and the code around it: [code]. Find out why it's undefined and show me the fixed code.
Other errors
CORS errorThe browser blocks your page from fetching data from another site404 Not FoundThe address or file can't be foundis not definedUsing a name that was never declaredSyntaxErrorBrackets or quotes don't match upExposed API keyYou put a secret key in your code or on GitHubMixed ContentAn https page loads something from an http addressBlank white pageYou deployed it and all you see is a blank screenis not a functionCalling something that isn't a functionUnexpected token < in JSONYou expected JSON but got HTMLCannot use import statement outside a moduleThe browser won't accept your import statementfavicon.ico 404The console shows a 404 for favicon.icoData disappears when I refreshYour to-dos or scores aren't being savedPage looks broken or tiny on phonesFine on a computer, weird on mobilegit push rejectedA "rejected" / non-fast-forward errornpm: command not foundYour terminal says npm or node doesn't existPort 3000 is already in useYour dev server says the port is takenEnvironment variables (.env) aren't loadingYou put your API key in .env but it comes out undefinedThe AI keeps failing to fix the same errorYou ask for a fix and nothing changes