# 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… **Computer Science** | **Grade 10** *A free lesson plan from K12 Academics. Source page: https://lessonplans.k12academics.com/k12-lesson-g10-cs-scope.html* 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. **Copy link** works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment. ## 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. Why does a variable sometimes work in one place but not another? Project each one and have students answer about variable scope. ## 50 minutes, five moves Tap any phase to open the teacher moves and student actions. ### Hook — Not Found 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. ### Use — Scope Students learn. #### 👩‍🏫 Teacher Moves - Send students to Variable Scope. - Note local vs global. - Note where each works. #### 🎒 Student Actions - Answer. - Note it. - Note it. ### Modify — Trace It Students practice. #### 👩‍🏫 Teacher Moves - Spot a local variable. - Spot a global one. - Predict where each works. #### 🎒 Student Actions - Local. - Global. - Predict. ### Create — Create Students apply. #### 👩‍🏫 Teacher Moves - Write a function with a local variable. - Try to use it outside. - Fix the scope. #### 🎒 Student Actions - Write. - Test. - Fix. ### Reflect — Reflect 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. ## Built to the standards you report on Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students. Understand variable scope. Document variable use. Debug scope errors. Reason about program state. ## One lesson, every learner ### Multilingual Learners - Scope diagram. - Frame: "a local variable works ___." - Trace a small program. ### Support & Access - Local vs global only. - Use a diagram. - Use examples. ### Stretch & Extend - Explore the global keyword. - Nest function scopes. - Debug a scope bug. ### What to gather - 📽️Screen / board - 🔍Scope diagram - 💻Variable Scope - 💻Code editor - 📓Notebooks - 🎫Exit-ticket slips ### Key terms - **scope**: where a variable is usable - **local**: inside a function only - **global**: across the whole program - **variable**: a named value - **function**: a reusable code block - **accessible**: able to be used - **namespace**: where names live - **bug**: a program error ## Exit Ticket Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students. ### Reflect: variable scope. Have students trace local vs global scope in a program. A printable scope sheet is in the CS library. ## Check your understanding **1. What does “scope” mean?** - where a variable is usable *(correct)* - where names live - a reusable code block - across the whole program “scope” means: where a variable is usable **2. Which word means: “inside a function only”?** - accessible - function - local *(correct)* - bug “local” means: inside a function only **3. What does “global” mean?** - a named value - across the whole program *(correct)* - able to be used - a reusable code block “global” means: across the whole program **4. Which word means: “a named value”?** - function - namespace - accessible - variable *(correct)* “variable” means: a named value **5. What does “function” mean?** - where names live - able to be used - across the whole program - a reusable code block *(correct)* “function” means: a reusable code block **6. Which word means: “able to be used”?** - global - function - namespace - accessible *(correct)* “accessible” means: able to be used ## Printable worksheet --- Full lesson page: https://lessonplans.k12academics.com/k12-lesson-g10-cs-scope.html All lessons: https://lessonplans.k12academics.com/