❗var is a statement❗️
🚧 under construction
Last updated
🚧 under construction
Last updated
JS ⟩ variable ⟩ var ⟩ var is statement
(side effects)
var is a statement, instead of a declaration:
it doesn't follow normal lexical scoping rules.
📘 JS spec ⟩ Variable Statement
var statement declares variable(s) that are scoped to the running execution context's VariableEnvironment.
var variable(s) 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.