Question presented to candidate: "Null reference errors are one of the most common JavaScript crashes. How does TypeScript help you avoid them, and which operators and patterns do you use day to day to handle values that might be missing?"
What a strong answer should cover:
- `strictNullChecks` (part of `strict`, since TypeScript 2.0) takes `null` and `undefined` out of every type, so "may be missing" must be written as `T | null` or `T | undefined`
- Narrowing removes them: `!== null`, `== null` (matches both null and undefined), truthiness checks (and their trap with `0` and `""`), early returns
- Operators: `??` falls back only on null/undefined, unlike `||`; `?.` short-circuits to `undefined`
- Library signatures that can miss: `Array.prototype.find`, `Map.get`, and `NonNullable<T>`
- The non-null assertion `!` only silences the compiler and does no run-time check
- Narrowing limits: callbacks over a reassigned `let`, and `filter` needing an explicit type predicate before TypeScript 5.5
Code / implementation expected: Yes β a function returning `T | null`, the compiler error when it is used unchecked, and the `??` versus `||` difference.