EMZETT.
Login

Cannot read properties of undefined (JavaScript)

In short: An attempt was made to access a property of undefined or null.

In more detail: The browser names the property, for example “reading ‘length’”.

In Depth

Possible causes

  • Data not loaded yet.
  • Wrong name or path.
  • Object was not created.

Solutions

  1. Use optional chaining (obj?.name).
  2. Check the value with console.log.
  3. Wait for loaded data (async/await).

See also: JS, TypeScript