Find: Missing Null Check
Find the Mistake Easy
Question
This code has a type error with strictNullChecks. Find the mistake:
Code
function getName(user: { name: string } | null): string {
return user.name;
}
Hint
The user parameter can be null. What happens if you access .name on null?
Explanation
The parameter user can be null, but the function accesses user.name without checking for null first. TypeScript errors: Object is possibly 'null'. Fix: add a null check: if (user === null) return ""; return user.name; or use optional chaining: return user?.name ?? "";.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.