Guided Notes

Null, Undefined & Strict Mode

strictNullChecks, optional chaining, nullish coalescing, the non-null assertion, definite assignment, and handling missing data safely.

The billion-dollar mistake

Slide 1 / 4

"Cannot read properties of undefined" is one of the most common JavaScript runtime errors. With strictNullChecks (part of strict mode), TypeScript treats null and undefined as separate types:

let user: User | undefined = users.find((u) => u.id === 7); user.name; // error: 'user' is possibly 'undefined'.

You must handle the missing case before using the value β€” the compiler turns a runtime crash into a compile-time reminder.