From the course: Learning Functional Programming with JavaScript (ES5)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Passing functions as arguments

Passing functions as arguments - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript (ES5)

Start my 1-month free trial

Passing functions as arguments

- [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…

Contents