๐var
๐ง under construction
Stop using varโ ( ๐see whyโ)
( โญ var is a statement, not a declarationโ)
declares a variable in function scope / global scope ( and does a lot of side effectsโ).
var
is a reserved wordโ
is a statement, not a declarationโ( ๐ var is a statementโ๏ธโ)
doesn't have block scope. ( ๐ var has no block scopeโ๏ธโ)
๐ compare๏ผ function declaration
in global scope,
var / function are implemented as global object propertyโ
these properties cannot be deleted with deleteโ
Variable Statement
var statement declares variables that are scoped to the running execution context's VariableEnvironment.
var variables are created when their containing Environment Record is instantiated and are initialized to undefined when created.
Within the scope of any VariableEnvironment a common BindingIdentifier may appear in more than one VariableDeclaration but those declarations collectively define only one variable.
A variable defined by a VariableDeclaration with an Initializer is assigned the value of its Initializer's AssignmentExpression when the VariableDeclaration is executed, not when the variable is created.
๐ JS spec โฉ Variable Statement
Last updated
Was this helpful?