Understanding Function Overloads
Obviously, the solution here is to use function overloads.
Function overloads allow us to overload a function with different call signatures and different return types based on what is passed in.
Overloads require you to use the
function keyword, but you do not have to include an implementation
0:00 The solution here is obviously to use function overloads. Function overloads allow you to overload a function with different call signatures. Those call signatures can have different return types based on what's passed in. You need to use the function keyword for this. That's what we'll do. We'll say function returnWhatIPassIn and refactor this here.
0:22 What we can do is add different function overloads on top of this. We can say function returnWhatIPassIn, same thing again. Let's say we handle the case where t is 1, and we're going to return 1. You notice, I don't need to provide an implementation signature here. We've got duplicate function implementation. All I need to do is just give it an extra little function signature on top.
0:46 When we pass in 1, then that's going to return 1. If I do the same thing for matt here, then it's going to return matt there. Both of our cases now pass. We're going to be covering function overloads and all their depth in this section. I'm sure you have questions, but promise you, I will answer them further down in the next exercise.