📜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.
Last updated