We show how JavaScript's treatment of functions as variables can be used to pass functions as arguments to other functions. We go through some examples of how this concept can be used to improve our code.
- [Narrator] Now let's how functions can be passed…as arguments and some of the ways…that this can be used in our code.…You're already familiar with passing values to functions.…When we pass values as arguments,…essentially what they do is change the data…that the function operates on.…For example, if we have some simple functions…that combine two numbers using some operations,…the arguments we pass in specify what those numbers are.…But what if instead of passing arguments…to specify what our data is,…we passed in arguments to specify…what was done to that data.…
JavaScript let's us do just that by allowing us…to pass functions as arguments.…In other words instead of passing values…we're passing actions.…This is likely a somewhat strange concept…if you're coming from object oriented programming…so let's go over a few examples…showing how this can be used.…Just for the sake of an example, take a look at this code.…In this simple program we have this repeated pattern…where if a condition met we call some function.…
Released
7/14/2017- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments
Share this video
Embed this video
Video: Passing functions as arguments