Unary operator (Definition)

An operator that requires only one operand to create an expression.

Availability:

ECMAScript edition - 2

Unary operators are those that operate on a single value or expression result.

Some of the unary operators use keywords to convey their meaning. Others are sequences of punctuation characters. Here are the unary operators defined by ECMAScript:

OperatorMeaning
+Convert the operand to a numeric value.
++Increment the numeric value of the operand.
-Convert the operand to a numeric value and negate it.
--Decrement the numeric value of the operand.
~Convert the operand to a 32 bit integer and perform a bitwise complement on it.
!Convert the operand to a boolean value and reverse its value.
newInvokes an object constructor
deleteUsed to delete a property from an object if it can be deleted.
voidRegardless of the result of evaluating the expression that may be operated on, this will always yield the undefined value.

Some of these operators have a different meaning when used with more than one operand.

See also:Add (+), Bitwise NOT - complement (~), delete, Expression, Logical NOT - complement (!), Negation operator (-), Operator, Operator Precedence, Positive value (+), Postfix operator, Prefix operator, Ternary operator, typeof, Unary expression, void

Cross-references:

ECMA 262 edition 2 - section - 11.4

ECMA 262 edition 3 - section - 11.4

Wrox Instant JavaScript - page - 19