Compound statement (Definition)

A block of code handled as if it were one statement.

A compound statement is a block of one or more statements gathered together and executed as if they were a single statement. This is a somewhat wordy description of what a function declaration provides. Other similar uses are the code that is iterated in a while or for loop and the code that is conditionally executed in an if ... else construct.

Any variables created within a compound statement will be local to the enclosing function if the compound statement exists inside a function's execution context, otherwise they will be globally scoped. In JavaScript you cannot localize the scope of a variable to within an if(), while(), or for() construct in the way that you can in C language.

See also:Definition, for( ... in ... ) ..., Function code, if( ... ) ..., if( ... ) ... else ..., Scope chain, Statement, var, while( ... ) ...