Logical NOT - complement (!) (Operator/logical)

Logical NOT operator.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:Boolean primitive
JavaScript syntax:-!anOperand
Argument list:anOperandA Boolean value to be complemented

The result is the Boolean complement of the operand value.

The exclamation mark is the logical negation operator. The operand is evaluated and its result converted to a binary value. The value is then reversed and used to replace the expression in whatever context it has been used.

The truth table shows the result of this operator for a Boolean primitive value:

ANOT
falsetrue
truefalse

Although this is classified as a logical operator here, it is also classified as a unary operator since it only has one operand.

The associativity is from right to left.

Refer to the operator precedence topic for details of execution order.

Example code:

   <HTML>

   <HEAD></HEAD>

   <BODY>

   <TABLE BORDER=1 CELLPADDING=2>

   <TR>

   <TH>A</TH>

   <TH>NOT</TH>

   </TR>

   <SCRIPT>

   for(a=0; a<2; a++)

   {

      document.write("<TR ALIGN=CENTER><TD>");

      document.write(Boolean(a));

      document.write("</TD><TD>");

      document.write(Boolean(!a));

      document.write("</TD></TR>");

   }

   </SCRIPT>

   </TABLE>

   </BODY>

   </HTML>

See also:Associativity, Bitwise NOT - complement (~), Logical operator, NOT Equal to (!=), Operator Precedence, Unary expression, Unary operator

Cross-references:

ECMA 262 edition 2 - section - 11.4.9

ECMA 262 edition 3 - section - 11.4.9