Why this matters
Prevents runtime TypeError crashes and makes fallback behavior explicit.
When accessing properties that may be absent, use optional chaining and sensible defaults.
Prevents runtime TypeError crashes and makes fallback behavior explicit.
Side-by-side examples engineers can pattern-match during review.
const city = user.address.city.toLowerCase();const city = user?.address?.city?.toLowerCase() ?? 'unknown';user.address.cityuser?.address?.city ?? 'unknown'From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.