14.3 Declarations and the Variable Statement
14.3.1 Let and Const Declarations
let
and const
declarations define variables that are scoped to the let
declaration does not have an
Syntax
14.3.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if the
BoundNames ofBindingList contains"let" . -
It is a Syntax Error if the
BoundNames ofBindingList contains any duplicate entries.
-
It is a Syntax Error if
Initializer is not present andIsConstantDeclaration of theLexicalDeclaration containing thisLexicalBinding istrue .
14.3.1.2 Runtime Semantics: Evaluation
- Perform ?
Evaluation ofBindingList . - Return
empty .
- Perform ?
Evaluation ofBindingList . - Return ?
Evaluation ofLexicalBinding .
- Let lhs be !
ResolveBinding (StringValue ofBindingIdentifier ). - Perform !
InitializeReferencedBinding (lhs,undefined ). - Return
empty .
A const
declaration.
- Let bindingId be
StringValue ofBindingIdentifier . - Let lhs be !
ResolveBinding (bindingId). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument bindingId.
- Let value be ?
- Else,
- Let rhs be ?
Evaluation ofInitializer . - Let value be ?
GetValue (rhs).
- Let rhs be ?
- Perform !
InitializeReferencedBinding (lhs, value). - Return
empty .
- Let rhs be ?
Evaluation ofInitializer . - Let value be ?
GetValue (rhs). - Let env be the
running execution context 's LexicalEnvironment. - Return ?
BindingInitialization ofBindingPattern with arguments value and env.
14.3.2 Variable Statement
A var
statement declares variables that are scoped to the
Syntax
14.3.2.1 Runtime Semantics: Evaluation
- Perform ?
Evaluation ofVariableDeclarationList . - Return
empty .
- Perform ?
Evaluation ofVariableDeclarationList . - Return ?
Evaluation ofVariableDeclaration .
- Return
empty .
- Let bindingId be
StringValue ofBindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument bindingId.
- Let value be ?
- Else,
- Let rhs be ?
Evaluation ofInitializer . - Let value be ?
GetValue (rhs).
- Let rhs be ?
- Perform ?
PutValue (lhs, value). - Return
empty .
If a
- Let rhs be ?
Evaluation ofInitializer . - Let rval be ?
GetValue (rhs). - Return ?
BindingInitialization ofBindingPattern with arguments rval andundefined .
14.3.3 Destructuring Binding Patterns
Syntax
14.3.3.1 Runtime Semantics: PropertyBindingInitialization
The
- Let boundNames be ?
PropertyBindingInitialization ofBindingPropertyList with arguments value and environment. - Let nextNames be ?
PropertyBindingInitialization ofBindingProperty with arguments value and environment. - Return the
list-concatenation of boundNames and nextNames.
- Let name be the sole element of the
BoundNames ofSingleNameBinding . - Perform ?
KeyedBindingInitialization ofSingleNameBinding with arguments value, environment, and name. - Return « name ».
- Let P be ?
Evaluation ofPropertyName . - Perform ?
KeyedBindingInitialization ofBindingElement with arguments value, environment, and P. - Return « P ».
14.3.3.2 Runtime Semantics: RestBindingInitialization
The
- Let lhs be ?
ResolveBinding (StringValue ofBindingIdentifier , environment). - Let restObj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform ?
CopyDataProperties (restObj, value, excludedNames). - If environment is
undefined , return ?PutValue (lhs, restObj). - Return ?
InitializeReferencedBinding (lhs, restObj).
14.3.3.3 Runtime Semantics: KeyedBindingInitialization
The
When
It is defined piecewise over the following productions:
- Let v be ?
GetV (value, propertyName). - If
Initializer is present and v isundefined , then- Let defaultValue be ?
Evaluation ofInitializer . - Set v to ?
GetValue (defaultValue).
- Let defaultValue be ?
- Return ?
BindingInitialization ofBindingPattern with arguments v and environment.
- Let bindingId be
StringValue ofBindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId, environment). - Let v be ?
GetV (value, propertyName). - If
Initializer is present and v isundefined , then- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Set v to ?
NamedEvaluation ofInitializer with argument bindingId.
- Set v to ?
- Else,
- Let defaultValue be ?
Evaluation ofInitializer . - Set v to ?
GetValue (defaultValue).
- Let defaultValue be ?
- If
- If environment is
undefined , return ?PutValue (lhs, v). - Return ?
InitializeReferencedBinding (lhs, v).