Statements and declarations

var declaration

Try the free JavaScript compiler

Declares a variable scoped to the surrounding function or applicable top-level context. In an ordinary function the binding is initialized to undefined before body execution; the initializer runs in statement order. An ordinary block does not isolate var. Conflicting lexical declarations can cause early errors.

Formal Syntax & Structure

javascript syntaxjavascript
var name = expression;

Parameters & Attributes

NameTypeDescription
nameBindingIdentifierName of the binding.
expressionexpressionOptional initializer evaluated at declaration execution.

Working Example

Example Snippetjavascript
function amount() { { var n = 11; } return n; }console.log(amount());
JavaScript Reference