A junior developer is tasked with fixing a bug where a variable is unexpectedly undefined. The developer suspects the variable is not within scope. Which programming concept describes where a variable can be accessed?
Trap 1: Loop
A loop is used to repeat a block of code, not to define variable accessibility.
Trap 2: Data type
Data types define the kind of data a variable can hold, not where it can be accessed.
Trap 3: Function
A function is a block of code that performs a task, not a concept for variable accessibility.
- A
Loop
Why wrong: A loop is used to repeat a block of code, not to define variable accessibility.
- B
Scope
Scope determines the visibility and lifetime of a variable within a program.
- C
Data type
Why wrong: Data types define the kind of data a variable can hold, not where it can be accessed.
- D
Function
Why wrong: A function is a block of code that performs a task, not a concept for variable accessibility.