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:
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.
<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>
Prev | Home | Next |
Logical expression | Up | Logical operator |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |