Basic Syntax

Scope

English

Overview

The range within which a variable, for example, can be referenced.

Details

The rule defining the range within which an identifier can be referenced, such as block scope or function scope, with rules varying by language. JavaScript's var has function scope, so using it inside a for loop means every iteration shares the same variable -- a classic source of bugs, since it produces unintended values (let's block scope avoids this).

More Programming terms