13.5 Unary Operators
Syntax
13.5.1 The delete
Operator
13.5.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if the
UnaryExpression is contained instrict mode code and the derivedUnaryExpression is .PrimaryExpression : IdentifierReference -
It is a Syntax Error if the derived
UnaryExpression is
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
andCoverParenthesizedExpressionAndArrowParameterList ultimately derives a phrase that, if used in place ofUnaryExpression , would produce a Syntax Error according to these rules. This rule is recursively applied.
The last rule means that expressions such as delete (((foo)))
produce early errors because of recursive application of the first rule.
13.5.1.2 Runtime Semantics: Evaluation
- Let ref be the result of evaluating
UnaryExpression . ReturnIfAbrupt (ref).- If ref is not a
Reference Record , returntrue . - If
IsUnresolvableReference (ref) istrue , thenAssert : ref.[[Strict]] isfalse .- Return
true .
- If
IsPropertyReference (ref) istrue , then- If
IsSuperReference (ref) istrue , throw aReferenceError exception. - Let baseObj be !
ToObject (ref.[[Base]]). - Let deleteStatus be ? baseObj.[[Delete]](ref.[[ReferencedName]]).
- If deleteStatus is
false and ref.[[Strict]] istrue , throw aTypeError exception. - Return deleteStatus.
- If
- Else,
- Let base be ref.[[Base]].
Assert : base is anEnvironment Record .- Return ? base.DeleteBinding(ref.[[ReferencedName]]).
When a delete
operator occurs within delete
operator occurs within
The object that may be created in step
13.5.2 The void
Operator
13.5.2.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Perform ?
GetValue (expr). - Return
undefined .
13.5.3 The typeof
Operator
13.5.3.1 Runtime Semantics: Evaluation
- Let val be the result of evaluating
UnaryExpression . - If val is a
Reference Record , then- If
IsUnresolvableReference (val) istrue , return"undefined" .
- If
- Set val to ?
GetValue (val). - Return a String according to
Table 37 .
Type of val | Result |
---|---|
Undefined |
|
Null |
|
Boolean |
|
Number |
|
String |
|
Symbol |
|
BigInt |
|
Object (does not implement [[Call]]) |
|
Object (implements [[Call]]) |
|
An additional entry related to [[IsHTMLDDA]] Internal Slot can be found in
13.5.4 Unary +
Operator
The unary + operator converts its operand to Number type.
13.5.4.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Return ?
ToNumber (?GetValue (expr)).
13.5.5 Unary -
Operator
The unary -
operator converts its operand to Number type and then negates it. Negating
13.5.5.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - Let T be
Type (oldValue). - Return ! T::unaryMinus(oldValue).
13.5.6 Bitwise NOT Operator ( ~
)
13.5.6.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - Let T be
Type (oldValue). - Return ! T::bitwiseNOT(oldValue).
13.5.7 Logical NOT Operator ( !
)
13.5.7.1 Runtime Semantics: Evaluation
- Let expr be the result of evaluating
UnaryExpression . - Let oldValue be !
ToBoolean (?GetValue (expr)). - If oldValue is
true , returnfalse . - Return
true .