What error type is thrown when accessing a property of undefined?
Answer
TypeError
Answer
TypeError
The error type thrown when accessing a property of `undefined` is `TypeError`.
`undefined` is a primitive value that does not contain properties. An expression such as `user.name` throws a `TypeError` when `user` is `undefined`, because JavaScript cannot perform property access on a missing value. Modern V8-based environments commonly report this as “Cannot read properties of undefined.”
This is different from a `ReferenceError`. A `ReferenceError` occurs when code refers to an identifier that does not exist in the accessible scope, such as `console.log(account)` when `account` was never declared. A `SyntaxError` indicates invalid JavaScript grammar, while a `RangeError` generally concerns a value outside an allowed range or excessive recursion.
The same kind of `TypeError` can occur with `null`, which is also not a property-bearing object. Optional chaining, such as `user?.name`, avoids the exception by returning `undefined` when the value on the left is `null` or `undefined`.
Source: Wikipedia · fact-checked Aug. 2026