2.1.11

Scope

Test yourself

Scope

The scope of a variable is the group of areas of the code from which it can be accessed.

Illustrative background for Local scopeIllustrative background for Local scope ?? "content

Local scope

  • A variable defined within a subroutine will have local scope.
  • This means that they can only be accessed within that subroutine.
Illustrative background for Global scopeIllustrative background for Global scope ?? "content

Global scope

  • A variable can be made global by adding the 'global' keyword in front of it when it is first used.
  • Global variables may be accessed by any part of the whole program.

Jump to other topics

1Computational Thinking & Algorithms

2Programming

3Hardware & Software

4Data

5The Internet

6Online Safety & Security

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson