0 of 6 problems solved0%
2 of 6

Print Full Name (Optional Last)

Optional properties are declared with ? and may be undefined. You’ll accept an object with a required first and an optional last, and build a full name. This teaches how to guard optional properties before using them.

Your Task

  • Complete the function printFullName(p: { first: string; last?: string }): string.
  • If last exists, return first + ' ' + last.
  • Otherwise, return just first.

Examples

  • printFullName({ first: 'Bob' }) → 'Bob'
  • printFullName({ first: 'Alice', last: 'Alisson' }) → 'Alice Alisson'