โvar is a statementโ๏ธ
๐ง under construction
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.
Last updated
Was this helpful?