When strict null checks are on, null and undefined must be handled explicitly. This helps you avoid crashes from missing values:
function greet(name: string | null) {
if (name === null) return "Hello, guest!";
return `Hello, ${name}!`;
}Key operators for handling maybe-values:
value ?? defaultValue (fallback for null/undefined)user?.address?.city (safe nested property access)const displayName = user.name ?? "Anonymous";
const city = user?.address?.city;In this category, you'll:
null and undefined with explicit checks?? for clean default values?. to safely access nested properties0, "", false)Best practice: Prefer small, clear checks. Don't rely on general truthy/falsy rules when you specifically want to treat null or undefined as missing.