Attempting to access a property on an undefined or null value.
This is one of the most frequent JavaScript errors. It occurs when you try to access a property or call a method on a value that is `undefined` or `null`. JavaScript allows you to evaluate almost anything, but accessing a property of `undefined` is a hard stop.
This error commonly happens when: a function returns `undefined` instead of an object, an API response is different from what you expected, an async operation hasn't completed yet when you try to access its result, or you access a nested object property whose parent doesn't exist.
1const user = {2 name: "Alice",3 address: null4};5 6// Accessing a property of null (user.address is null)7console.log(user.address.city);1const user = {2 name: "Alice",3 address: null4};5 6// Fix 1: Optional chaining (?.) — returns undefined instead of throwing7const city = user?.address?.city;8console.log(city); // undefined9 10// Fix 2: Nullish coalescing for a default value11const cityName = user?.address?.city ?? "City not provided";12console.log(cityName); // "City not provided"13 14// Fix 3: Traditional guard15if (user.address && user.address.city) {16 console.log(user.address.city);17}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
`user.address` is `null`, not an object. When JavaScript tries to evaluate `null.city`, it raises `TypeError: Cannot read properties of null (reading 'city')`. The same error occurs if `address` were `undefined`. JavaScript cannot traverse property paths through `null` or `undefined`.