Essential Types And Notations 20 exercises
Problem

Optional Function Parameters

Here we have a concatName function, whose implementation takes in two string parameters first and last.

If there's no last name passed, the return would be just the first name. Otherwise, it would return first concatenated with last:


const concatName = (first: string

Loading exercise

Transcript

00:00 Here we have a CONCATNAME function, and this CONCATNAME function takes in two parameters, a first and a last. If there's no last name passed, then we just return the first name. Otherwise, we return first concatenated with last. Nice. So here we have some usage examples

00:17 where we have result equals CONCATNAME John Doe, so we can happily pass in both arguments. And now result should be of type string, and it is. Here we have CONCATNAME, and CONCATNAME expected two arguments, but got one. This error should not be happening. We should be able to just pass in the first name

00:36 and then return just the first name. So this last parameter on the CONCATNAME function, it should be optional. So your job is to work out how to annotate that as optional and then give it that type. Good luck.