Language concepts

Function scope

Try the free JavaScript compiler

An ordinary function establishes an environment for parameters and local declarations. A var declared inside its ordinary nested blocks remains in the function scope. Code outside the function cannot read those local bindings by name. Lexical declarations may have narrower nested scopes.

Formal Syntax & Structure

javascript syntaxjavascript
function report() { var total = 4; return total; }

Working Example

Example Snippetjavascript
function report() { var total = 4; return total; }console.log(report());
JavaScript Reference