Home›Lesson Plans›Computer Science›Programming · Grade 10

Variable Scope

Tenth graders learn variable scope — where in a program a variable can be used. Local variables live inside their function; global variables work across the program. Understanding scope prevents a whole class of bugs. They check the ideas, then trace scope in code.

Grade 10Variable Scope50 minutes1 class periodCSTA / ISTEExplicit teaching4 StandardsCSTA
Start the Lesson
Assign or share this lesson

Copy link works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment.

Lesson at a Glance

Everything you need before the bell rings

Learning Objectives

Students will be able to…

  • ✓Define scope.
  • ✓Tell local from global.
  • ✓Avoid scope bugs.
  • ✓Trace scope.
Essential Question

Why does a variable sometimes work in one place but not another?

0
Lesson Phases
0
Vocabulary Terms
0
Standards Aligned
0
Interactive Task
Check It · Interactive

Variable Scope

Project each one and have students answer about variable scope.

🔍 Understand variable scopeTry it
Answer each question about variable scope.
The Lesson · Explicit teaching

50 minutes, five moves

Tap any phase to open the teacher moves and student actions.

1

Hook — Not Found

5 min

Why might a variable give a "not defined" error in one spot?

👩‍🏫 Teacher Moves

  • Pose the question.
  • Share ideas.
  • Set the goal.

🎒 Student Actions

  • Think.
  • Share.
  • Get ready.
2

Use — Scope

12 min

Students learn.

👩‍🏫 Teacher Moves

  • Send students to Variable Scope.
  • Note local vs global.
  • Note where each works.

🎒 Student Actions

  • Answer.
  • Note it.
  • Note it.
3

Modify — Trace It

13 min

Students practice.

👩‍🏫 Teacher Moves

  • Spot a local variable.
  • Spot a global one.
  • Predict where each works.

🎒 Student Actions

  • Local.
  • Global.
  • Predict.
4

Create — Create

15 min

Students apply.

👩‍🏫 Teacher Moves

  • Write a function with a local variable.
  • Try to use it outside.
  • Fix the scope.

🎒 Student Actions

  • Write.
  • Test.
  • Fix.
5

Reflect — Reflect

5 min

Students close.

👩‍🏫 Teacher Moves

  • What is scope?
  • Where does a local variable work?
  • Complete the exit ticket.

🎒 Student Actions

  • Say it.
  • Say it.
  • Complete the exit ticket.
Standards Alignment

Built to the standards you report on

Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students.

CSTA
3A-AP-14

Understand variable scope.

CSTA
3A-AP-18

Document variable use.

CSTA
3A-AP-17

Debug scope errors.

ISTE
5c

Reason about program state.

Differentiation

One lesson, every learner

Multilingual Learners

ELL / EMERGING READERS
  • Scope diagram.
  • Frame: "a local variable works ___."
  • Trace a small program.

Support & Access

IEP / 504
  • Local vs global only.
  • Use a diagram.
  • Use examples.

Stretch & Extend

GIFTED / EARLY FINISHERS
  • Explore the global keyword.
  • Nest function scopes.
  • Debug a scope bug.
Materials

What to gather

  • 📽️Screen / board
  • 🔍Scope diagram
  • 💻Variable Scope
  • 💻Code editor
  • 📓Notebooks
  • 🎫Exit-ticket slips
Vocabulary

Key terms — hover for a quick definition

scopewhere a variable is usablelocalinside a function onlyglobalacross the whole programvariablea named valuefunctiona reusable code blockaccessibleable to be usednamespacewhere names livebuga program error
Evaluate

Exit Ticket

Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students.

QUESTION 1
What is variable scope?
Where in the code a variable can be used.
QUESTION 2
Where does a local variable work?
Only inside its function.
QUESTION 3
Where does a global variable work?
Across the whole program.

Reflect: variable scope.

Have students trace local vs global scope in a program. A printable scope sheet is in the CS library.

Study · Flashcards

Study the key terms

Tap a card to flip it, then rate whether you knew it. Built from this lesson’s vocabulary.

🃏 Variable ScopeFlip
Card 1
Term
Tap to flip →
Meaning
0

Nice work!

Practice · Quiz

Check your understanding

A quick self-check with instant feedback, drawn from this lesson’s key terms.

📝 Variable ScopeQuiz
Score: 0
1 / 6
Question 1
0%

Nice work!

Practice · Worksheet

Printable worksheet

A print-and-go review sheet with a built-in answer key. Tap “Show answer key” to reveal answers, or print the clean version for students.

🖨️ Variable ScopePrint
Name: ________________________
Date: ____________

Part A · Write the word that matches each meaning

Word bank: accessible, bug, function, global, local, namespace, scope, variable
  1. where a variable is usable
  2. a program error
  3. across the whole program
  4. inside a function only
  5. a named value
  6. a reusable code block
  7. where names live
  8. able to be used

Part B · Show what you learned

  1. What is variable scope?
  2. Where does a local variable work?
  3. Where does a global variable work?
Answer key — Part A: 1) scope · 2) bug · 3) global · 4) local · 5) variable · 6) function · 7) namespace · 8) accessible
Part B: 1) Where in the code a variable can be used. 2) Only inside its function. 3) Across the whole program.