Syntax
The this keyword evaluates to the this value of the execution context.
An Identifier is evaluated using the scoping rules stated in 10.1.4. The result of evaluating an Identifier is always a value of type Reference.
A Literal is evaluated as described in 7.8.
An array initialiser is an expression describing the initialisation of an Array object, written in a form of a literal. It is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets. The elements need not be literals; they are evaluated each time the array initialiser is evaluated.
Array elements may be elided at the beginning, middle or end of the element list. Whenever a comma in the element list is not preceded by an AssignmentExpression (i. e., a comma at the beginning or after another comma), the missing array element contributes to the length of the Array and increases the index of subsequent elements. Elided array elements are not defined.
Syntax
Semantics
The production ArrayLiteral : [ Elisionopt ] is evaluated as follows:
1. Create a new array as if by the expression new Array().
2. Evaluate Elision; if not present, use the numeric value zero.
3. Call the [[Put]] method of Result(1) with arguments "length" and Result(2).
4. Return Result(1).
The production ArrayLiteral : [ ElementList ] is evaluated as follows:
1. Evaluate ElementList.
2. Return Result(1).
The production ArrayLiteral : [ ElementList , Elisionopt ] is evaluated as follows:
1. Evaluate ElementList.
2. Evaluate Elision; if not present, use the numeric value zero.
3. Call the [[Get]] method of Result(1) with argument "length".
4. Call the [[Put]] method of Result(1) with arguments "length" and (Result(2)+ Result(3)).
5. Return Result(1).
The production ElementList : Elisionopt AssignmentExpression is evaluated as follows:
1. Create a new array as if by the expression new Array().
2. Evaluate Elision; if not present, use the numeric value zero.
3. Evaluate AssignmentExpression.
4. Call GetValue(Result(3)).
5. Call the [[Put]] method of Result(1) with arguments Result(2) and Result(4).
6. Return Result(1)
The production ElementList : ElementList , Elisionopt AssignmentExpression is evaluated as follows:
1. Evaluate ElementList.
2. Evaluate Elision; if not present, use the numeric value zero.
3. Evaluate AssignmentExpression.
4. Call GetValue(Result(3)).
5. Call the [[Get]] method of Result(1) with argument "length".
6. Call the [[Put]] method of Result(1) with arguments (Result(2)+ Result(5)) and Result(4).
7. Return Result(1)
The production Elision : , is evaluated as follows:
1. Return the numeric value 1.
The production Elision : Elision , is evaluated as follows:
1. Evaluate Elision.
2. Return (Result(1)+ 1).
An object initialiser is an expression describing the initialisation of an Object, written in a form resembling a literal. It is a list of zero or more pairs of property names and associated values, enclosed in curly braces. The values need not be literals; they are evaluated each time the object initialiser is evaluated.
Syntax
Semantics
The production ObjectLiteral : {} is evaluated as follows:
1. Create a new object as if by the expression new Object().
2. Return Result(1).
The production ObjectLiteral : { PropertyNameAndValueList } is evaluated as follows:
1. Evaluate PropertyNameAndValueList.
2. Return Result(1);
The production PropertyNameAndValueList : PropertyName : AssignmentExpression is evaluated as follows:
1. Create a new object as if by the expression new Object().
2. Evaluate PropertyName.
3. Evaluate AssignmentExpression.
4. Call GetValue(Result(3)).
5. Call the [[Put]] method of Result(1) with arguments Result(2) and Result(4).
6. Return Result(1).
The production PropertyNameAndValueList : PropertyNameAndValueList , PropertyName : AssignmentExpression is evaluated as follows:
1. Evaluate PropertyNameAndValueList.
2. Evaluate PropertyName.
3. Evaluate AssignmentExpression.
4. Call GetValue(Result(3)).
5. Call the [[Put]] method of Result(1) with arguments Result(2) and Result(4).
6. Return Result(1).
The production PropertyName : Identifier is evaluated as follows:
1. Form a string literal containing the same sequence of characters as the Identifier.
2. Return Result(1).
The production PropertyName : StringLiteral is evaluated as follows:
1. Return the value of the StringLiteral.
The production PropertyName : NumericLiteral is evaluated as follows:
1. Form the value of the NumericLiteral.
2. Return ToString(Result(1)).
The production PrimaryExpression : ( Expression ) is evaluated as follows:
1. Evaluate Expression. This may be of type Reference.
2. Return Result(1).
NOTE
This algorithm does not apply GetValue to Result(1). The principal
motivation for this is so that operators such as
delete and typeof
may be applied to parenthesised expressions.
Syntax
Properties are accessed by name, using either the dot notation:
MemberExpression . Identifier
CallExpression . Identifier
or the bracket notation:
MemberExpression [ Expression
]
CallExpression [ Expression
]
The dot notation is explained by the following syntactic conversion:
MemberExpression . Identifier
is identical in its behaviour to
MemberExpression [ <identifier-string> ]
and similarly
CallExpression . Identifier
is identical in its behaviour to CallExpression [ <identifier-string> ]
where <identifier-string> is a string literal containing the same sequence of characters as the Identifier.
The production MemberExpression : MemberExpression [ Expression ] is evaluated as follows:
1. Evaluate MemberExpression.
2. Call GetValue(Result(1)).
3. Evaluate Expression.
4. Call GetValue(Result(3)).
5. Call ToObject(Result(2)).
6. Call ToString(Result(4)).
7. Return a value of type Reference whose base object is Result(5) and whose property name is Result(6).
The production CallExpression : CallExpression [ Expression ] is evaluated in exactly the same manner, except that the contained CallExpression is evaluated in step 1.
The production NewExpression : new NewExpression is evaluated as follows:
1. Evaluate NewExpression.
2. Call GetValue(Result(1)).
3. If Type(Result(2)) is not Object, throw a TypeError exception.
4. If Result(2) does not implement the internal [[Construct]] method, throw a TypeError exception.
5. Call the [[Construct]] method on Result(2), providing no arguments (that is, an empty list of arguments).
6. Return Result(5).
The production MemberExpression : new MemberExpression Arguments is evaluated as follows:
1. Evaluate MemberExpression.
2. Call GetValue(Result(1)).
3. Evaluate Arguments, producing an internal list of argument values (11.2.4).
4. If Type(Result(2)) is not Object, throw a TypeError exception.
5. If Result(2) does not implement the internal [[Construct]] method, throw a TypeError exception.
6. Call the [[Construct]] method on Result(2), providing the list Result(3) as the argument values.
7. Return Result(6).
The production CallExpression : MemberExpression Arguments is evaluated as follows:
1. Evaluate MemberExpression.
2. Evaluate Arguments, producing an internal list of argument values (see 11.2.4).
3. Call GetValue(Result(1)).
4. If Type(Result(3)) is not Object, throw a TypeError exception.
5. If Result(3) does not implement the internal [[Call]] method, throw a TypeError exception.
6. If Type(Result(1)) is Reference, Result(6) is GetBase( Result(1)). Otherwise, Result(6) is null.
7. If Result(6) is an activation object, Result(7) is null. Otherwise, Result(7) is the same as Result(6).
8. Call the [[Call]] method on Result(3), providing Result(7) as the this value and providing the list Result(2) as the argument values.
9. Return Result(8).
The production CallExpression : CallExpression Arguments is evaluated in exactly the same manner, except that the contained CallExpression is evaluated in step 1.
NOTE
Result(8) will never be of type Reference if Result(3) is a native
ECMAScript object. Whether calling a host object can return a value of
type Reference is implementation-dependent.
The evaluation of an argument list produces an internal list of values (see 8.8).
The production Arguments : () is evaluated as follows:
1. Return an empty internal list of values.
The production Arguments : ( ArgumentList ) is evaluated as follows:
1. Evaluate ArgumentList.
2. Return Result(1).
The production ArgumentList : AssignmentExpression is evaluated as follows:
1. Evaluate AssignmentExpression.
2. Call GetValue(Result(1)).
3. Return an internal list whose sole item is Result(2).
The production ArgumentList : ArgumentList , AssignmentExpression is evaluated as follows:
1. Evaluate ArgumentList.
2. Evaluate AssignmentExpression.
3. Call GetValue(Result(2)).
4. Return an internal list whose length is one greater than the length of Result(1) and whose items are the items of Result(1), in order, followed at the end by Result(3), which is the last item of the new list.
The production MemberExpression : FunctionExpression is evaluated as follows:
1. Evaluate FunctionExpression.
2. Return Result(1).
Syntax
The production PostfixExpression : LeftHandSideExpression [no LineTerminator here] ++ is evaluated as follows:
1. Evaluate LeftHandSideExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. Add the value 1 to Result(3), using the same rules as for the + operator (see 11.6.3).
5. Call PutValue(Result(1), Result(4)).
6. Return Result(3).
The production PostfixExpression : LeftHandSideExpression [no LineTerminator here] -- is evaluated as follows:
1. Evaluate LeftHandSideExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. Subtract the value 1 from Result(3), using the same rules as for the - operator (11.6.3).
5. Call PutValue(Result(1), Result(4)).
6. Return Result(3).
Syntax
The production UnaryExpression : delete UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. If Type(Result(1)) is not Reference, return true.
3. Call GetBase(Result(1)).
4. Call GetPropertyName(Result(1)).
5. Call the [[Delete]] method on Result(3), providing Result(4) as the property name to delete.
6. Return Result(5).
The production UnaryExpression : void UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Return undefined.
The production UnaryExpression : typeof UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. If Type(Result(1)) is not Reference, go to step 4.
3. If GetBase(Result(1)) is null, return "undefined".
4. Call GetValue(Result(1)).
5. Return a string determined by Type(Result(4)) according to the following table:
Type | Result |
---|---|
Undefined | "undefined" |
Null | "object" |
Boolean | "boolean" |
Number | "number" |
String | "string" |
Object (native and doesn't implement [[Call]]) | "object" |
Object (native and implements [[Call]]) | "function" |
Object (host) | Implementation-dependent |
The production UnaryExpression : ++ UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. Add the value 1 to Result(3), using the same rules as for the + operator (see 11.6.3).
5. Call PutValue(Result(1), Result(4)).
6. Return Result(4).
The production UnaryExpression : -- UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. Subtract the value 1 from Result(3), using the same rules as for the - operator (see 11.6.3).
5. Call PutValue(Result(1), Result(4)).
6. Return Result(4).
The unary + operator converts its operand to Number type.
The production UnaryExpression : + UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. Return Result(3).
The unary - operator converts its operand to Number type and then negates it. Note that negating +0 produces -0, and negating -0 produces +0.
The production UnaryExpression : - UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToNumber(Result(2)).
4. If Result(3) is NaN, return NaN.
5. Negate Result(3); that is, compute a number with the same magnitude but opposite sign.
6. Return Result(5).
The production UnaryExpression : ~ UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToInt32(Result(2)).
4. Apply bitwise complement to Result(3). The result is a signed 32-bit integer.
5. Return Result(4).
The production UnaryExpression : ! UnaryExpression is evaluated as follows:
1. Evaluate UnaryExpression.
2. Call GetValue(Result(1)).
3. Call ToBoolean(Result(2)).
4. If Result(3) is true, return false.
5. Return true.
Syntax
Semantics
The production MultiplicativeExpression : MultiplicativeExpression @ UnaryExpression, where @ stands for one of the operators in the above definitions, is evaluated as follows:
1. Evaluate MultiplicativeExpression.
2. Call GetValue(Result(1)).
3.Evaluate UnaryExpression.
4.Call GetValue(Result(3)).
5.Call ToNumber(Result(2)).
6.Call ToNumber(Result(4)).
7.Apply the specified operation (*, /, or %) to Result(5) and Result(6). See the notes below (11.5.1, 11.5.2, 11.5.3).
8.Return Result(7).
The * operator performs multiplication, producing the product of its operands. Multiplication is commutative. Multiplication is not always associative in ECMAScript, because of finite precision.
The result of a floating-point multiplication is governed by the rules of IEEE 754 double-precision arithmetic:
The / operator performs division, producing the quotient of its operands. The left operand is the dividend and the right operand is the divisor. ECMAScript does not perform integer division. The operands and result of all division operations are double-precision floating-point numbers. The result of division is determined by the specification of IEEE 754 arithmetic:
The % operator yields the remainder of its operands from an implied division; the left operand is the dividend and the right operand is the divisor.
NOTE
In C and C++, the remainder operator accepts only integral operands; in
ECMAScript, it also accepts floating-point operands.
The result of a floating-point remainder operation as computed by the % operator is not the same as the "remainder" operation defined by IEEE 754. The IEEE 754 "remainder" operation computes the remainder from a rounding division, not a truncating division, and so its behaviour is not analogous to that of the usual integer remainder operator. Instead the ECMAScript language defines % on floating-point operations to behave in a manner analogous to that of the Java integer remainder operator; this may be compared with the C library function fmod.
The result of a ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:
The addition operator either performs string concatenation or numeric addition.
The production AdditiveExpression : AdditiveExpression + MultiplicativeExpression is evaluated as follows:
1. Evaluate AdditiveExpression.
2.Call GetValue(Result(1)).
3.Evaluate MultiplicativeExpression.
4.Call GetValue(Result(3)).
5.Call ToPrimitive(Result(2)).
6.Call ToPrimitive(Result(4)).
7.If Type(Result(5)) is String or Type(Result(6)) is String, go to step 12. (Note that this step differs from step 3 in the comparison algorithm for the relational operators, by using or instead of and.)
8.Call ToNumber(Result(5)).
9.Call ToNumber(Result(6)).
10. Apply the addition operation to Result(8) and Result(9). See the note below (11.6.3).
11. Return Result(10).
12. Call ToString(Result(5)).
13. Call ToString(Result(6)).
14. Concatenate Result(12) followed by Result(13).
15. Return Result(14).
NOTE
No hint is provided in the calls to ToPrimitive in steps 5 and 6. All
native ECMAScript objects except Date objects handle the absence of a
hint as if the hint Number were given; Date objects handle the absence
of a hint as if the hint String were given. Host objects may handle the
absence of a hint in some other manner.
The production AdditiveExpression : AdditiveExpression - MultiplicativeExpression is evaluated as follows:
1. Evaluate AdditiveExpression.
2.Call GetValue(Result(1)).
3.Evaluate MultiplicativeExpression.
4.Call GetValue(Result(3)).
5.Call ToNumber(Result(2)).
6.Call ToNumber(Result(4)).
7.Apply the subtraction operation to Result(5) and Result(6). See the note below (11.6.3).
8.Return Result(7).
The + operator performs addition when applied to two operands of numeric type, producing the sum of the operands. The - operator performs subtraction, producing the difference of two numeric operands.
Addition is a commutative operation, but not always associative.
The result of an addition is determined using the rules of IEEE 754 double-precision arithmetic:
The - operator performs subtraction when applied to two operands of numeric type, producing the difference of its operands; the left operand is the minuend and the right operand is the subtrahend. Given numeric operands a and b, it is always the case that a- b produces the same result as a+(- b).
Syntax
Performs a bitwise left shift operation on the left operand by the amount specified by the right operand.
The production ShiftExpression : ShiftExpression << AdditiveExpression is evaluated as follows:
1. Evaluate ShiftExpression.
2.Call GetValue(Result(1)).
3.Evaluate AdditiveExpression.
4. Call GetValue(Result(3)).
5.Call ToInt32(Result(2)).
6.Call ToUint32(Result(4)).
7.Mask out all but the least significant 5 bits of Result(6), that is, compute Result(6) & 0x1F.
8.Left shift Result(5) by Result(7) bits. The result is a signed 32 bit integer.
9.Return Result(8).
Performs a sign-filling bitwise right shift operation on the left operand by the amount specified by the right operand.
The production ShiftExpression : ShiftExpression >> AdditiveExpression is evaluated as follows:
1. Evaluate ShiftExpression.
2.Call GetValue(Result(1)).
3.Evaluate AdditiveExpression.
4. Call GetValue(Result(3)).
5.Call ToInt32(Result(2)).
6.Call ToUint32(Result(4)).
7.Mask out all but the least significant 5 bits of Result(6), that is, compute Result(6) & 0x1F.
8.Perform sign-extending right shift of Result(5) by Result(7) bits. The most significant bit is propagated. The result is a signed 32 bit integer.
9.Return Result(8).
Performs a zero-filling bitwise right shift operation on the left operand by the amount specified by the right operand.
The production ShiftExpression : ShiftExpression >>> AdditiveExpression is evaluated as follows:
1. Evaluate ShiftExpression.
2.Call GetValue(Result(1)).
3.Evaluate AdditiveExpression.
4. Call GetValue(Result(3)).
5.Call ToUint32(Result(2)).
6.Call ToUint32(Result(4)).
7.Mask out all but the least significant 5 bits of Result(6), that is, compute Result(6) & 0x1F.
8.Perform zero-filling right shift of Result(5) by Result(7) bits. Vacated bits are filled with zero. The result is an unsigned 32 bit integer.
9.Return Result(8).
Syntax
NOTE
The 'NoIn' variants are needed to avoid confusing the
in operator in a relational expression with the
in operator in a for
statement.
Semantics
The result of evaluating a relational operator is always of type Boolean, reflecting whether the relationship named by the operator holds between its two operands.
The RelationalExpressionNoIn productions are evaluated in the same manner as the RelationalExpression productions except that the contained RelationalExpressionNoIn is evaluated instead of the contained RelationalExpression.
The production RelationalExpression : RelationalExpression < ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(2) < Result(4). (see 11.8.5)
6.If Result(5) is undefined, return false. Otherwise, return Result(5).
The production RelationalExpression : RelationalExpression > ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) < Result(2). (see 11.8.5).
6.If Result(5) is undefined, return false. Otherwise, return Result(5).
The production RelationalExpression : RelationalExpression <= ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) < Result(2). (see 11.8.5).
6.If Result(5) is true or undefined, return false. Otherwise, return true.
The production RelationalExpression : RelationalExpression >= ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(2) < Result(4). (see 11.8.5).
6.If Result(5) is true or undefined, return false. Otherwise, return true.
The comparison x < y, where x and y are values, produces true, false, or undefined (which indicates that at least one operand is NaN). Such a comparison is performed as follows:
1. Call ToPrimitive(x, hint Number).
2. Call ToPrimitive(y, hint Number).
3.If Type(Result(1)) is String and Type(Result(2)) is String, go to step 16. (Note that this step differs from step 7 in the algorithm for the addition operator + in using and instead of or.)
4.Call ToNumber(Result(1)).
5.Call ToNumber(Result(2)).
6.If Result(4) is NaN, return undefined.
7.If Result(5) is NaN, return undefined.
8.If Result(4) and Result(5) are the same number value, return false.
9.If Result(4) is +0 and Result(5) is -0, return false.
10. If Result(4) is -0 and Result(5) is +0, return false.
11. If Result(4) is +∞, return false.
12. If Result(5) is +∞, return true.
13. If Result(5) is -∞, return false.
14. If Result(4) is -∞, return true.
15. If the mathematical value of Result(4) is less than the mathematical value of Result(5) --- note that these mathematical values are both finite and not both zero --- return true. Otherwise, return false.
16.If Result(2) is a prefix of Result(1), return false. (A string value p is a prefix of string value q if q can be the result of concatenating p and some other string r. Note that any string is a prefix of itself, because r may be the empty string.)
17. If Result(1) is a prefix of Result(2), return true.
18.Let k be the smallest nonnegative integer such that the character at position k within Result(1) is different from the character at position k within Result(2). (There must be such a k, for neither string is a prefix of the other.)
19. Let m be the integer that is the code point value for the character at position k within Result(1).
20. Let n be the integer that is the code point value for the character at position k within Result(2).
21. If m < n, return true. Otherwise, return false.
NOTE
The comparison of strings uses a simple lexicographic ordering on
sequences of code point value values. There is no attempt to use the
more complex, semantically oriented definitions of character or string
equality and collating order defined in the Unicode specification.
Therefore strings that are canonically equal according to the Unicode
standard could test as unequal. In effect this algorithm assumes that
both strings are already in normalised form.
The production RelationalExpression: RelationalExpression instanceof ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.If Result(4) is not an object, throw a TypeError exception.
6.If Result(4) does not have a [[HasInstance]] method, throw a TypeError exception.
7.Call the [[HasInstance]] method of Result(4) with parameter Result(2).
8.Return Result(7).
The production RelationalExpression : RelationalExpression in ShiftExpression is evaluated as follows:
1. Evaluate RelationalExpression.
2.Call GetValue(Result(1)).
3.Evaluate ShiftExpression.
4.Call GetValue(Result(3)).
5.If Result(4) is not an object, throw a TypeError exception.
6.Call ToString(Result(2)).
7.Call the [[HasProperty]] method of Result(4) with parameter Result(6).
8.Return Result(7).
Syntax
Semantics
The result of evaluating an equality operator is always of type Boolean, reflecting whether the relationship named by the operator holds between its two operands.
The EqualityExpressionNoIn productions are evaluated in the same manner as the EqualityExpression productions except that the contained EqualityExpressionNoIn and RelationalExpressionNoIn are evaluated instead of the contained EqualityExpression and RelationalExpression, respectively.
The production EqualityExpression : EqualityExpression == RelationalExpression is evaluated as follows:
1. Evaluate EqualityExpression.
2.Call GetValue(Result(1)).
3.Evaluate RelationalExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) == Result(2). (see 11.9.3).
6.Return Result(5).
The production EqualityExpression : EqualityExpression != RelationalExpression is evaluated as follows:
1. Evaluate EqualityExpression.
2.Call GetValue(Result(1)).
3.Evaluate RelationalExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) == Result(2). (see 11.9.3).
6.If Result(5) is true, return false. Otherwise, return true.
The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:
1. If Type(x) is different from Type(y), go to step 14.
2.If Type(x) is Undefined, return true.
3.If Type(x) is Null, return true.
4.If Type(x) is not Number, go to step 11.
5.If x is NaN, return false.
6.If y is NaN, return false.
7.If x is the same number value as y, return true.
8.If x is +0 and y is -0, return true.
9. If x is -0 and y is +0, return true.
10. Return false.
11.If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.
12. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
13.Return true if x and y refer to the same object or if they refer to objects joined to each other (see 13.1.2). Otherwise, return false.
14. If x is null and y is undefined, return true.
15. If x is undefined and y is null, return true.
16.If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
17.If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x)== y.
18. If Type(x) is Boolean, return the result of the comparison ToNumber(x)== y.
19. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
20.If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
21.If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x)== y.
22. Return false.
NOTE
Given the above definition of equality:
String comparison can be forced by: ""+a ==""+ b.
Numeric comparison can be forced by: a -0 ==b -0.
Boolean comparison can be forced by: !a == !b.
The equality operators maintain the following invariants:
A != B is equivalent to !(A == B).
A == B is equivalent to B == A, except in the order of evaluation of A and B.
The equality operator is not always transitive. For example, there might be two distinct String objects, each representing the same string value; each String object would be considered equal to the string value by the== operator, but the two String objects would not be equal to each other.
Comparison of strings uses a simple equality test on sequences of code point value values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode 2.0 specification. Therefore strings that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both strings are already in normalised form.
The production EqualityExpression : EqualityExpression === RelationalExpression is evaluated as follows:
1. Evaluate EqualityExpression.
2.Call GetValue(Result(1)).
3.Evaluate RelationalExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) === Result(2). (See below.)
6.Return Result(5).
The production EqualityExpression : EqualityExpression !== RelationalExpression is evaluated as follows:
1. Evaluate EqualityExpression.
2.Call GetValue(Result(1)).
3.Evaluate RelationalExpression.
4.Call GetValue(Result(3)).
5.Perform the comparison Result(4) === Result(2). (See below.)
6.If Result(5) is true, return false. Otherwise, return true.
The comparison x === y, where x and y are values, produces true or false. Such a comparison is performed as follows:
1.If Type(x) is different from Type(y), return false.
2.If Type(x) is Undefined, return true.
3.If Type(x) is Null, return true.
4.If Type(x) is not Number, go to step 11.
5.If x is NaN, return false.
6.If y is NaN, return false.
7.If x is the same number value as y, return true.
8.If x is +0 and y is -0, return true.
9.If x is -0 and y is +0, return true.
10. Return false.
11.If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions); otherwise, return false.
12. If Type(x) is Boolean, return true if x and y are both true or both false; otherwise, return false.
13.Return true if x and y refer to the same object or if they refer to objects joined to each other (see 13.1.2). Otherwise, return false.
Syntax
Semantics
The production A : A @B, where @ is one of the bitwise operators in the productions above, is evaluated as follows:
1. Evaluate A.
2.Call GetValue(Result(1)).
3.Evaluate B.
4.Call GetValue(Result(3)).
5.Call ToInt32(Result(2)).
6.Call ToInt32(Result(4)).
7.Apply the bitwise operator @ to Result(5) and Result(6). The result is a signed 32 bit integer.
8.Return Result(7).
Syntax
Semantics
The production LogicalANDExpression : LogicalANDExpression && BitwiseORExpression is evaluated as follows:
1. Evaluate LogicalANDExpression.
2.Call GetValue(Result(1)).
3.Call ToBoolean(Result(2)).
4.If Result(3) is false, return Result(2).
5.Evaluate BitwiseORExpression.
6.Call GetValue(Result(5)).
7.Return Result(6).
The production LogicalORExpression : LogicalORExpression || LogicalANDExpression is evaluated as follows:
1. Evaluate LogicalORExpression.
2.Call GetValue(Result(1)).
3.Call ToBoolean(Result(2)).
4.If Result(3) is true, return Result(2).
5. Evaluate LogicalANDExpression.
6.Call GetValue(Result(5)).
7.Return Result(6).
The LogicalANDExpressionNoIn and LogicalORExpressionNoIn productions are evaluated in the same manner as the LogicalANDExpression and LogicalORExpression productions except that the contained LogicalANDExpressionNoIn, BitwiseORExpressionNoIn and LogicalORExpressionNoIn are evaluated instead of the contained LogicalANDExpression, BitwiseORExpression and LogicalORExpression, respectively.
NOTE
The value produced by a && or
|| operator is not necessarily of type
Boolean. The value produced will always be the value of one of the two
operand expressions.
Syntax
Semantics
The production ConditionalExpression : LogicalORExpression ? AssignmentExpression : AssignmentExpression is evaluated as follows:
1. Evaluate LogicalORExpression.
2.Call GetValue(Result(1)).
3.Call ToBoolean(Result(2)).
4.If Result(3) is false, go to step 8.
5. Evaluate the first AssignmentExpression.
6. Call GetValue(Result(5)).
7.Return Result(6).
8. Evaluate the second AssignmentExpression.
9. Call GetValue(Result(8)).
10. Return Result(9).
The ConditionalExpressionNoIn production is evaluated in the same manner as the ConditionalExpression production except that the contained LogicalORExpressionNoIn, AssignmentExpression and AssignmentExpressionNoIn are evaluated instead of the contained LogicalORExpression, first AssignmentExpression and second AssignmentExpression, respectively.
NOTE
The grammar for a ConditionalExpression in ECMAScript is a little bit
different from that in C and Java, which each allow the second
subexpression to be an Expression but restrict the third expression to
be a ConditionalExpression. The motivation for this difference in
ECMAScript is to allow an assignment expression to be governed by
either arm of a conditional and to eliminate the confusing and fairly
useless case of a comma expression as the centre expression.
Syntax
Semantics
The AssignmentExpressionNoIn productions are evaluated in the same manner as the AssignmentExpression productions except that the contained ConditionalExpressionNoIn and AssignmentExpressionNoIn are evaluated instead of the contained ConditionalExpression and AssignmentExpression, respectively.
The production AssignmentExpression : LeftHandSideExpression = AssignmentExpression is evaluated as follows:
1. Evaluate LeftHandSideExpression.
2. Evaluate AssignmentExpression.
3.Call GetValue(Result(2)).
4.Call PutValue(Result(1), Result(3)).
5.Return Result(3).
The production AssignmentExpression : LeftHandSideExpression @ = AssignmentExpression, where @ represents one of the operators indicated above, is evaluated as follows:
1. Evaluate LeftHandSideExpression.
2.Call GetValue(Result(1)).
3.Evaluate AssignmentExpression.
4.Call GetValue(Result(3)).
5.Apply operator @ to Result(2) and Result(4).
6.Call PutValue(Result(1), Result(5)).
7.Return Result(5).
Syntax
Semantics
The production Expression : Expression , AssignmentExpression is evaluated as follows:
1.Evaluate Expression.
2.Call GetValue(Result(1)).
3.Evaluate AssignmentExpression.
4.Call GetValue(Result(3)).
5.Return Result(4).
The ExpressionNoIn production is evaluated in the same manner as the Expression production except that the contained ExpressionNoIn and AssignmentExpressionNoIn are evaluated instead of the contained Expression and AssignmentExpression, respectively.