Programming ConceptsLesson 10Free preview
Scope
This lesson is part of Intro to Programming · All levels
Summary
This lesson discusses scope, the rules of the region of action of a variable in a program. The local variable can only be accessed within the function or block where it is created, whereas the global variable is alive throughout the program. Understanding the scope prevents name collisions and makes bugs related to variables much easier to avoid.
Key points
- Scope determines where a variable can be accessed
- Local variables are only visible within the constructor function/block
- Global variables can be accessed from anywhere in the program
- Narrow scope reduces name and bug conflicts
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.