0 of 6 problems solved0%
1 of 6

Greet Maybe Name

null and undefined mean a value is missing. With strict null checks, you must handle them. Use nullish coalescing (??) to pick a fallback only when the value is null or undefined.

const raw: string | undefined = undefined;
const safe = raw ?? "fallback"; // 'fallback'

Optional chaining (?.) helps when you want to read a property only if the value exists. Keep the rule simple: treat only null and undefined as missing.

Your Task

Create a greeter that handles missing names.

  • Write function greet(name: string | null | undefined): string.
  • Return "Hi, <name>!" when a real string is provided.
  • When name is null or undefined, return "Hi, there!".
  • Do not trim or change the provided name.