This course has been updated! We now recommend you take the Functional-Light JavaScript, v3 course.
Transcript from the "Exercise 2 Solution" Lesson
[00:00:00]
>> [MUSIC]
[00:00:04]
>> Mike: First off, the readme says we're gonna need to care about only the first two parameters passed in. Quick, easiest way to do that is to give those names. You could have messed around with the arguments array if you really wanted to, but here, I'm gonna just cheat and use just the two names, which means if you pass in any other arguments, I'm just gonna ignore them, kay?
[00:00:23] Now, I need to return a function. I'm going to be lazy and not give it a name, cuz it doesn't really matter here, but function expressions generally should have names. That function, as we see the way it's being used, if we look at the test cases, if you will, the way it's being used, doesn't take any arguments, so I don't need an argument here.
[00:00:42] And the readme said that what we wanted to do with that is add those two values together and return it. So that's all we have to do.
>> Mike: Can we see that it's closed over both x and y? The parameters act, in this case, like local variables that have a value.
[00:01:01] Those values don't change over time. So, over time, as I'm calling x over and over and over again, x and y are still always the 3 and the 4 value respectively, which is what gives us that value 7 each time, okay? As silly and stupid as this is, being able to do that at a whim, being able to put a function and wrap it around some state, and maintain that state, is one of the most important things you can get, if you wanna use functional programming techniques, functional light, if you will, in your programs.
[00:01:37] Having a mastery over closure is really important. That's why I said at the beginning that it's so fundamental to programming, it's so much the most important thing. I literally can't count how many different places that closure shows up in programming techniques.