Local variables
Variables declared within functions or blocks with scope limited to that region. Local variables are created when execution enters their scope and destroyed on exit. Each function call receives its own copy of local variables. Local scope improves code modularity and prevents naming conflicts.
Real World
When Netflix's recommendation algorithm runs a sorting function, the temporary comparison variables are local — they vanish once the function returns, freeing memory for the next user's request.
Exam Focus
Emphasise that local variables are destroyed when the function ends — this lifecycle distinction is a common exam differentiator.
How well did you know this?