Welcome to Functions You Can Pass Around! In JavaScript, a function is a value, like a number or a string. You can store it, pass it, and hand it to another function to call later.
In this course, you’ll build a movie-night picker for Tomás. His friends share a watchlist of films, and picking one takes them half an hour. The picker drops the films over two hours, lists the ones nobody has seen, and finds the first comedy that fits. It checks that every film has a vote, then prints a shortlist:
$ node picker.js
Films that fit: Paddington 2, The Grand Budapest Hotel, Arrival, Coco
Nobody has seen: Arrival
First comedy that fits: Paddington 2
Every film has a vote: false
Shortlist:
1. Coco (4 votes, 105 min)
2. Arrival (4 votes, 116 min)
3. Paddington 2 (3 votes, 104 min)
4. The Grand Budapest Hotel (0 votes, 99 min)
Instead of writing a loop for every question, you’ll hand small functions to array methods that do the looping.
What You’ll Learn
By the end of this course, you’ll be able 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
A callback is a function you hand to another function to call.
Before You Start
You should be able to write programs in Node with values, strings, decisions, functions, and loops, and you should know how to work with arrays, objects, and lists of records. You’ll need a current Node LTS, a terminal, and any editor.
How the Course Works
You’ll read text lessons, watch short videos, and run every example in your terminal. Each section ends with a browser exercise, checked by tests. At the end, you’ll explain your picker in a mentor chat on the site and take a quiz.
Next, in Store Functions in Variables, you’ll treat a function like any other value.