Skip to content

JavaScript Tutorial Error Handling

Reading Browser Console Errors

Lesson 165 of 258 3 min read By Deepak Paswan Updated Oct 4, 2026

Error messages are not scary. They are the program telling you exactly where to look. Here is how to read one.

code
TEXT
Uncaught TypeError: Cannot read properties of undefined (reading 'name')
    at showUser (app.js:12:20)
    at HTMLButtonElement.<anonymous> (app.js:25:5)

The parts

  1. Uncaught: nothing handled this error.
  2. TypeError: the kind of error (error types).
  3. The message: what went wrong. Here: you tried to read .name of something that is undefined.
  4. The stack trace: the chain of function calls that led to it, most recent first. app.js:12:20 means file app.js, line 12, column 20.

Start with the first line of the stack that is in your own file, and click it. The console jumps to the code.

Try it

script.js
JS
const user = undefined;
console.log(user.name);   // error on purpose

Run it. The Try it console shows the message and the line. In a real browser console you also get the stack trace and a link to the exact line.

Common messages and what they mean

MessageUsual cause and fix
x is not definedtypo, or the variable is out of scope. Check the spelling and where it is declared.
Cannot read properties of undefined (reading 'y')the thing before .y is undefined. Print it to see why, or use ?..
Cannot read properties of nullquerySelector found nothing. Check the selector and when the script runs.
x is not a functionwrong name, wrong object, or something overwrote it. Check what x really is.
Assignment to constant variableyou reassigned a const. Use let, or do not reassign.
Unexpected tokena typo in syntax, or JSON that is really HTML.
Cannot access 'x' before initializationusing a let or const before its line.
Maximum call stack size exceededa function keeps calling itself (missing base case).
Failed to fetchnetwork failure, wrong URL or blocked by CORS.
Uncaught (in promise) ...a rejected promise nobody handled. Add catch or try...catch.

A debugging routine

  1. Read the message and the error type.
  2. Go to the line in the stack.
  3. Print what is there: console.log(value, typeof value).
  4. Work backwards: where did that value come from?
  5. Fix one thing, reload, and read the new message.

Warnings and other messages

  • Yellow warnings are not errors but are worth reading.
  • Network errors (red lines in the Network tab or the console) mean a request failed. Check the URL and the response.
  • Source maps: bundled code may show unreadable names. Developer tools can map them back to your original files.

The golden rule

Fix the first error. Many later errors are caused by it, and disappear once it is fixed.

lightbulb
Search smartly
If a message is new to you, search for the exact message text without your own variable names, plus “JavaScript”. Someone has almost certainly seen it before.