Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Functions You Can Pass Around (Summary)

You’ve finished Functions You Can Pass Around, and Tomás’s movie night has its picker. Most of what you built in the course rests on one idea: a function is a value, like a number or a string, so you can store it, pass it, and hand it to another function to call later.

In This Course, You Learned How To

  • Store functions in variables, pass them to other functions, and give parameters defaults
  • Keep a watchlist up to date and check what’s in it with array methods, and build records with shorthand
  • Transform, filter, search, and sort a list of records by handing functions to array methods
  • Build Tomás’s movie-night picker, and explain what each callback receives and returns

Things to Remember

  • filter(fitsTonight) hands the function over, and fitsTonight(film) calls it now.
  • When the argument is undefined, a default parameter fills in.
  • Ask every array method two questions: does it change the array, and what does it return?
  • The callback’s return value decides what map(), filter(), and find() give back.
  • Numbers need a comparator in sort() and toSorted() alike. The sort() method changes the array, and toSorted() returns a sorted copy.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ve finished Functions You Can Pass Around, and Tomás’s movie night has its picker. In this course, you learned how to store functions in variables, pass them to other functions, and give parameters defaults.

00:13 You learned how to keep a watchlist up to date and check what’s in it with array methods, and build records with shorthand. You learned how to transform, filter, search, and sort a list of records by handing functions to array methods.

00:27 And you built Tomás’s movie-night picker, and explained what each callback receives and returns.

00:35 Most of what you built works because a function is a value, like a number or a string. Tomás’s fitsTonight, written here as an arrow, is stored in a const like any other value.

00:48 You hand it to filter without parentheses, so filter receives the function itself. Then filter calls it with each film. Each call returns true or false, and filter keeps the films that got true.

01:02 Four of the six films fit. Sort those four by votes, then length, and the picker prints its shortlist, with Coco on top.

01:12 Things to remember. Without parentheses, a function’s name hands over the function. With them, you call it now. When the argument is undefined, a default parameter fills in.

01:25 For every array method, ask whether it changes the array, and what it returns. The callback’s return value decides what map, filter, and find give back. And numbers need a comparator in sort and toSorted alike.

01:39 Sort changes the array, and toSorted gives you a sorted copy.

01:46 The RealJS reference has pages on callbacks, arrow functions, and arrays.

01:53 Thanks for watching.

Become a Member to join the conversation.