Loading video player…

Scope, Closures and the Call Stack (Overview)

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:

Language: Text
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.

Download

Course Slides (.pdf)

2.3 MB
Download

Sample Code (.zip)

20.5 KB

00:00 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.

00:14 With both, you can follow bigger programs.

00:18 Here’s a first taste of the scorekeeping kit you’ll build for Marco, who hosts a weekly quiz at the Lantern pub.

00:26 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.

00:41 A lookup remembers best rounds, a round total walks nested categories like Music, and a pipeline ranks the teams.

00:50 By the end, you’ll be able to follow how nested and recursive calls run. You’ll find the declaration a name refers to, from where the code is written. You’ll build functions that remember state between calls.

01:04 You’ll compose small functions into pipelines. And you’ll build Marco’s scorekeeping kit, and explain how it works.

01:13 You should know arrow functions with array methods, .reduce(), Map and Set, and when two names share one object. You need a current Node LTS, a terminal, and any editor.

01:26 It’s course four on the Intermediate JavaScript path, and it stands on its own.

01:33 You’ll read 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.

01:49 A quiz closes the course. Next up: Follow Calls on the Call Stack.

Become a Member to join the conversation.