Free auditStart free
GuideError · Browser

Uncaught TypeError: Cannot read properties of undefined

JavaScript threw because code read a property of undefined or null. Find which value is empty, then fix it with a check, optional chaining or a default value.

4 min
read
4
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
In one line

Uncaught TypeError: Cannot read properties of undefined means your code tried to read a property from a value that is undefined. Find the value just before the dot in the message, work out why it's empty at that moment, then guard it with a check or optional chaining (?.), or fix the code that should have set it.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01The same error in each engine, per MDN

What the message means and who causes it

MDN files this error under "x is (not) y" and says it occurs "when there was an unexpected type. Oftentimes, unexpected undefined or null values." The error comes from your own code, or a script you load, and the browser is only reporting it. The text in brackets names the property you were reading, and the thing it was read from is the value that is empty.
Browser engine

V8-based (Chrome, Edge)

Message
TypeError: Cannot read properties of undefined (reading 'x')
Browser engine

Firefox

Message
TypeError: "x" is undefined, or TypeError: "undefined" is not an object
Browser engine

Safari

Message
TypeError: undefined is not an object (evaluating 'obj.x')

In Cannot read properties of undefined (reading 'id'), the word after reading is the property you asked for. The empty value is whatever you wrote before .id. A message that says null instead of undefined means that value is null; the fix is the same.

03Check it

Fix it

MDN gives two guards. Test the value first, or, if you're confident it won't be another falsy value such as "" or 0, test truthiness.

The shorter modern form is optional chaining. MDN says that if the object accessed or function called with ?. is undefined or null, the expression short-circuits and evaluates to undefined instead of throwing. It also warns that the older obj.first && obj.first.second pattern isn't safe for falsy values such as 0, and that ?. avoids that.

Optional chaining with a default
const city = customer?.city ?? "Unknown city";
const first = list?.[0];
const label = button?.getLabel?.();
Check before you read
if (foo !== undefined && foo !== null) {
  // Now we know that foo is defined, we are good to go.
}

if (foo) {
  // Now we know that foo is truthy, it will necessarily not be null/undefined.
}
04How it works

Track it down in two minutes

  1. 1

    Click the file and line

    Open DevTools, then Console. The error links to the exact line.

  2. 2

    Find the empty value

    Read the message. Everything left of the final dot in the failing expression is the candidate.

  3. 3

    Log it just before the line

    Use console.log on the value and on its parent. You're looking for the first link in the chain that is undefined or null.

  4. 4

    Ask when it was set

    If the value comes from a request, a script that loads later or a user action, the read may be running too early. Move the read, or render only once the data exists.

  5. 5

    Pick the guard

    Use a check if you need a different branch, or ?. with ?? if a default is fine.

A close relative is ReferenceError: x is not defined, which is thrown when the name itself doesn't exist, not when its value is empty.

05Explained

What it does to SEO

This error is raised by the browser's JavaScript engine, not returned by your server. If a script that produces text or links throws before it finishes, the page may render without them. See JavaScript SEO and rendering.
Sources · 4

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • mozilla.org
  1. 01MDN: TypeError: "x" is (not) "y"developer.mozilla.org · checked 2026-10-25
  2. 02MDN: Optional chaining (?.)developer.mozilla.org · checked 2026-10-25
  3. 03MDN: Document.querySelector()developer.mozilla.org · checked 2026-10-25
  4. 04MDN: undefineddeveloper.mozilla.org · checked 2026-10-25
Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01How do I fix "cannot read properties of undefined"?

Find the value before the dot, then find out why it is empty at that moment. Fix the source, or guard the read with a check or optional chaining.

02What is the difference between null and undefined here?

Both cause the same TypeError when you read a property from them. MDN lists null and undefined together as the usual unexpected values behind this error.

03Why does it say reading 'id'?

The name in quotes is the property your code tried to read. The empty value is the object you tried to read it from, so look at what comes before .id.

04Is optional chaining a fix?

It prevents the throw by returning undefined. It's right when the value may legitimately be missing. If the value should exist, it only hides the real bug.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane