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 ,MemberExpression : MemberExpression . PrivateIdentifier ,CallExpression : CallExpression . PrivateIdentifier , orOptionalChain : ?. PrivateIdentifier .OptionalChain : OptionalChain . PrivateIdentifier -
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
13.5.1.2 Runtime Semantics: Evaluation
- Let ref be ?
Evaluation ofUnaryExpression . - If ref is not a
Reference Record , returntrue . - If
IsUnresolvableReference (ref) istrue , thenAssert : ref.[[Strict]] isfalse .- Return
true .
- If
IsPropertyReference (ref) istrue , thenAssert :IsPrivateReference (ref) isfalse .- 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.
- 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 ?
Evaluation ofUnaryExpression . - Perform ?
GetValue (expr). - Return
undefined .
13.5.3 The typeof
Operator
13.5.3.1 Runtime Semantics: Evaluation
- Let val be ?
Evaluation ofUnaryExpression . - If val is a
Reference Record , then- If
IsUnresolvableReference (val) istrue , return"undefined" .
- If
- Set val to ?
GetValue (val). - If val is
undefined , return"undefined" . - If val is
null , return"object" . - If val
is a String , return"string" . - If val
is a Symbol , return"symbol" . - If val
is a Boolean , return"boolean" . - If val
is a Number , return"number" . - If val
is a BigInt , return"bigint" . Assert : valis an Object .- NOTE: This step is replaced in section
B.3.6.3 . - If val has a [[Call]] internal slot, return
"function" . - Return
"object" .
13.5.4 Unary +
Operator
The unary + operator converts its operand to
13.5.4.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Return ?
ToNumber (?GetValue (expr)).
13.5.5 Unary -
Operator
The unary -
operator converts its operand to a numeric value and then negates it. Negating
13.5.5.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , then- Return
Number::unaryMinus (oldValue).
- Return
- Else,
Assert : oldValueis a BigInt .- Return
BigInt::unaryMinus (oldValue).
13.5.6 Bitwise NOT Operator ( ~
)
13.5.6.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be ?
ToNumeric (?GetValue (expr)). - If oldValue
is a Number , then- Return
Number::bitwiseNOT (oldValue).
- Return
- Else,
Assert : oldValueis a BigInt .- Return
BigInt::bitwiseNOT (oldValue).
13.5.7 Logical NOT Operator ( !
)
13.5.7.1 Runtime Semantics: Evaluation
- Let expr be ?
Evaluation ofUnaryExpression . - Let oldValue be
ToBoolean (?GetValue (expr)). - If oldValue is
true , returnfalse . - Return
true .