Missing null or undefined guard
A value that can legitimately be absent is used as though it never is.
What it looks like
?.quietly becoming.in a diff.- A lookup —
find,get,match— whose result is used without checking it was found. - An early return for the missing case removed as 'dead code'.
Why it survives review
The happy path is the path everybody reads, and on the happy path the value is always there. The absent case usually arrives from somewhere else entirely — a stale id, an empty result, a config that has not been set — so it is not on the reviewer's mind while they are reading this function.
How to see it
- For every lookup, ask what happens when it finds nothing, and whether the type system was ever told that could happen.
- Treat a removed
?.as a claim: the author is asserting this can never be absent. Ask what makes that true. - Look at what the type says versus what the runtime can produce.
anyand a cast are where these hide.
A minimal pair
Correct
const owner = users.find((u) => u.id === id);
return owner?.name ?? 'unknown';
Defective
const owner = users.find((u) => u.id === id);
return owner.name;
An id that is not in the list throws instead of returning 'unknown'.
Practise it
1 diff in the corpus carry this class. They are not listed, because knowing which diff contains what would make finding it a comprehension question about this page.
Go to the exercises