Welcome to Scope, Closures and the Call Stack! Two pictures sit behind your functions. The call stack tracks the calls in progress. A closure lets a function keep using the variables in scope where it was created. With both pictures, you can follow what bigger programs do.
In this course, you’ll build a scorekeeping kit for Marco, who hosts a weekly quiz at the Lantern, a neighborhood pub. When it’s finished, the kit prints the final standings and the winner:
Know-It-Owls, Music: 8 points
Best round, The Lamplighters: 10
Best round, Know-It-Owls: 9
Best round, The Quizzards: 10
Best round, Second Guessers: 9
Best round, Table Six: 9
Final standings:
1. The Lamplighters: 40 points
2. The Quizzards: 37 points
3. Table Six: 35 points
4. Second Guessers: 31 points
5. Know-It-Owls: 30 points
The winner is The Lamplighters with 40 points!
Every week, Marco adds up scores on a notepad. Last week, a corrected score mixed him up, and he read the same winner twice. In his kit, each team’s scorer keeps its own total, and the winner is announced once. A lookup remembers best rounds, a round total walks nested categories like Music, and a pipeline ranks the teams.
What You’ll Learn
By the end of this course, you’ll be able to:
- Follow how nested and recursive calls run
- Find the declaration a name refers to, from where the code is written
- Build functions that remember state between calls
- Compose small functions into pipelines
- Build Marco’s scorekeeping kit, and explain how it works
Before You Start
You should know how to hand arrow functions to array methods, when two names share one object, and how to use .reduce(), Map and Set. You’ll need a current Node LTS, a terminal, and any editor.
This is the fourth course on the Intermediate JavaScript path, and it stands on its own.
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. In the project, you’ll build the kit, then talk it through in a chat with the RealJS mentor. A quiz closes the course.
Next up: Follow Calls on the Call Stack.