Essential Types And Notations 20 exercises
Problem

Default Parameters in JavaScript Functions

Here we have the same concatName function as before, where the last name is optional:


const concatName = (first: string, last?: string) => {
if (!last) {
return first;
}
return `${first} ${last}`;
};

We also have a couple of tests. This test checks that the function re

Loading exercise

Transcript

00:00 In this exercise, we have our CONCATNAME function back and everything looks like it's going okay, except for if you look in the tests here, it's expecting expected John to deeply equal John Pocock. And this is down the bottom here. It's expecting that when you call CONCATNAME with just John here,

00:18 it automatically defaults to John Pocock. So what it's saying here is it wants a default for the last name when it's passed to CONCATNAME here. So this is a little bit tricky. How are we going to add a default to our last? We could, of course, do it inside the function body,

00:36 but I would like you to find the right syntax for giving last a default of Pocock, which is my last name, of course. So good luck.