No matter how control leaves the
The value of a eval
function all return the value 1:
eval("1;;;;;")
eval("1;{}")
eval("1;var a;")
The abstract operation BlockDeclarationInstantiation takes arguments code (a
When a
It performs the following steps when called:
let
and const
declarations define variables that are scoped to the let
declaration does not have an
A const
declaration.
A var
statement declares variables that are scoped to the
If a
The syntax-directed operation PropertyBindingInitialization takes arguments value and environment. It collects a list of all bound property names rather than just empty completion. It is defined piecewise over the following productions:
The syntax-directed operation RestBindingInitialization takes arguments value, environment, and excludedNames. It is defined piecewise over the following productions:
The syntax-directed operation KeyedBindingInitialization takes arguments value, environment, and propertyName.
When
It is defined piecewise over the following productions:
An function
or class
async function
because that would make it ambiguous with an let [
because that would make it ambiguous with a let
if
Statementelse
] resolves the classic "dangling else" problem in the usual way. That is, when the choice of associated if
is otherwise ambiguous, the else
is associated with the nearest (innermost) of the candidate if
sIt is only necessary to apply this rule if the extension specified in
The abstract operation LoopContinues takes arguments completion and labelSet. It performs the following steps when called:
Within the
The syntax-directed operation LoopEvaluation takes argument labelSet. It is defined piecewise over the following productions:
do
-while
StatementIt is only necessary to apply this rule if the extension specified in
The syntax-directed operation DoWhileLoopEvaluation takes argument labelSet. It is defined piecewise over the following productions:
while
StatementIt is only necessary to apply this rule if the extension specified in
The syntax-directed operation WhileLoopEvaluation takes argument labelSet. It is defined piecewise over the following productions:
for
StatementIt is only necessary to apply this rule if the extension specified in
The syntax-directed operation ForLoopEvaluation takes argument labelSet. It is defined piecewise over the following productions:
The abstract operation ForBodyEvaluation takes arguments test, increment, stmt, perIterationBindings, and labelSet. It performs the following steps when called:
The abstract operation CreatePerIterationEnvironment takes argument perIterationBindings. It performs the following steps when called:
for
-in
, for
-of
, and for
-await
-of
StatementsThis section is extended by Annex
It is only necessary to apply this rule if the extension specified in
If
If
The syntax-directed operation IsDestructuring takes no arguments. It is defined piecewise over the following productions:
This section is extended by Annex
The syntax-directed operation ForDeclarationBindingInitialization takes arguments value and environment.
var
statements and the formal parameter lists of some
It is defined piecewise over the following productions:
The syntax-directed operation ForDeclarationBindingInstantiation takes argument environment. It is defined piecewise over the following productions:
The syntax-directed operation ForInOfLoopEvaluation takes argument labelSet. It is defined piecewise over the following productions:
This section is extended by Annex
The abstract operation ForIn/OfHeadEvaluation takes arguments uninitializedBoundNames, expr, and iterationKind (either
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs, stmt, iteratorRecord, iterationKind, lhsKind (either
The abstract operation EnumerateObjectProperties takes argument O (an Object). It performs the following steps when called:
next
method iterates over all the String-valued keys of enumerable properties of O. The iterator object is never directly accessible to ECMAScript code. The mechanics and order of enumerating the properties is not specified but must conform to the rules specified below.The iterator's throw
and return
methods are next
method processes object properties to determine whether the property key should be returned as an iterator value. Returned property keys do not include keys that are Symbols. Properties of the target object may be deleted during enumeration. A property that is deleted before it is processed by the iterator's next
method is ignored. If new properties are added to the target object during enumeration, the newly added properties are not guaranteed to be processed in the active enumeration. A next
method at most once in any enumeration.
Enumerating the properties of the target object includes enumerating properties of its prototype, and the prototype of the prototype, and so on, recursively; but a property of a prototype is not processed if it has the same name as a property that has already been processed by the iterator's next
method. The values of [[Enumerable]] attributes are not considered when determining if a property of a prototype object has already been processed. The enumerable property names of prototype objects must be obtained by invoking EnumerateObjectProperties passing the prototype object as the argument. EnumerateObjectProperties must obtain the own property keys of the target object by calling its [[OwnPropertyKeys]] internal method. Property attributes of the target object must be obtained by calling its [[GetOwnProperty]] internal method.
In addition, if neither O nor any object in its prototype chain is a
ECMAScript implementations are not required to implement the algorithm in
The following is an informative definition of an ECMAScript generator function that conforms to these rules:
function* EnumerateObjectProperties(obj) {
const visited = new Set();
for (const key of Reflect.ownKeys(obj)) {
if (typeof key === "symbol") continue;
const desc = Reflect.getOwnPropertyDescriptor(obj, key);
if (desc) {
visited.add(key);
if (desc.enumerable) yield key;
}
}
const proto = Reflect.getPrototypeOf(obj);
if (proto === null) return;
for (const protoKey of EnumerateObjectProperties(proto)) {
if (!visited.has(protoKey)) yield protoKey;
}
}
A For-In Iterator is an object that represents a specific iteration over some specific object. For-In Iterator objects are never directly accessible to ECMAScript code; they exist solely to illustrate the behaviour of
The abstract operation CreateForInIterator takes argument object (an Object). It is used to create a For-In Iterator object which iterates over the own and inherited enumerable string properties of object in a specific order. It performs the following steps when called:
The %ForInIteratorPrototype% object:
For-In Iterator instances are
Internal Slot | Description |
---|---|
[[Object]] | The Object value whose properties are being iterated. |
[[ObjectWasVisited]] |
|
[[VisitedKeys]] | A list of String values which have been emitted by this iterator thus far. |
[[RemainingKeys]] |
A list of String values remaining to be emitted for the current object, before iterating the properties of its prototype (if its prototype is not |
continue
Statementstatic
initialization block boundaries), within an break
Statementstatic
initialization block boundaries), within an return
StatementA return
statement causes a function to cease execution and, in most cases, returns a value to the caller. If return
statement may not actually return a value to the caller depending on surrounding context. For example, in a try
block, a return
statement's completion record may be replaced with another completion record during evaluation of the finally
block.
with
StatementThe with
statement adds an
It is only necessary to apply the second rule if the extension specified in
No matter how control leaves the embedded
switch
StatementThe syntax-directed operation CaseBlockEvaluation takes argument input. It is defined piecewise over the following productions:
The abstract operation CaseClauseIsSelected takes arguments C (a
This operation does not execute C's
No matter how control leaves the
A break
and continue
statements. ECMAScript has no goto
statement. A
An alternative definition for this rule is provided in
The abstract operation IsLabelledFunction takes argument stmt. It performs the following steps when called:
The syntax-directed operation LabelledEvaluation takes argument labelSet. It is defined piecewise over the following productions:
A
The only two productions of
throw
Statementtry
StatementThe try
statement encloses a block of code in which an exceptional condition can occur, such as a runtime error or a throw
statement. The catch
clause provides the exception-handling code. When a catch clause catches an exception, its
An alternative
The syntax-directed operation CatchClauseEvaluation takes argument thrownValue. It is defined piecewise over the following productions:
No matter how control leaves the
debugger
StatementEvaluating a