From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

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

Functions as data, continued

Functions as data, continued - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Functions as data, continued

- [Instructor] In this video we're going to look at another example of an interesting thing that can be done with first class functions. Just as we can create an array of numbers, an array of strings, or an array of objects. Because functions in JavaScript are first class we can also create an array of functions. And why would we want to do something like that exactly? Well let's say that we have a few different functions that we've created with our nice es6 arrow syntax. All of which take a single argument and make some sort of change to that argument. Like doubling it or subtracting from it or tripling it or adding five to it. Now let's say that we wanted to get the result of applying all of these functions to some number. The mechanical way of doing this would be to say something like const my number equals 42. And then we would apply our functions one by one to this number. So const doubled equals double my number. Const minus one equals subtract one called on doubled the result…

Contents