Logical (Boolean) Operators
|!||NOT||Returns false if its single value can be converted to true; otherwise returns true|
|||||OR||Returns true if either value is true|
|&&||AND||Returns true if both values are true|
Logical operators (also know as Boolean operators) are used for comparing two conditional statements. They are useful for checking a condition and then directing the script to proceed based on the outcome of that decision.
NOT Operator (!)
This operator is used to reverse the logical value of an expression. For instance,
!true would evaluate as false. The expression says, "NOT true,"
so it is false. Then also,
!false would evaluate as true.
would evaluate as false. The expression says, "the statement 25 is greater than
13 is false."
OR Operator (||)
This operator returns true if the expression on either side of the operator is true. For instance,
23>43 || 25==25 is true as the expression on the right side is true. Again,
23>43 || 23==43 is false because both expressions are false.
AND Operator (&&)
This operator returns true if the expressions on both sides of the operator are true. For instance,
5==5 && 16==16 is true as both expressions are true.
27>=32 && 33==33 is false because the first expression is false.
|>>>||Zero Fill Right Shift|
For the most part, these are used in advanced scripts in context with CGI scripts and Java applets. We won't go into detail about these here.
|?:||Conditional||A type of if...else statement. A condition is placed before the (?) and a value is placed on each side of the (:)|
|,||Comma||Used to process a series of expressions|
|delete||Delete||Deletes an object, property, or element from an array|
|in||In||Used to inspect the contents of a specified object|
|instanceof||Instanceof||Tests an object to see if it is of a specified object.|
|new||New||Creates an instance of an object|
|this||This||Refers to the current object|
|typeof||Typeof||Identifies the type of value being evaluated|
|void||Void||Evaluates an expression without returning a value|
These operators are used for specific tasks and can help eliminate unnecessary code. These will be discussed in greater detail in future lessons.
Order of Precedence
|( )||Overrides all others. Calculations done from the inside to the outside.|
|<<||Left Shift (Bitwise)|
|>>||Right Shift (Bitwise)|
|<=||Less Than or Equal To|
|>=||Greater Than or Equal To|
|+=||Add and Assign|
|-=||Subtract and Assign|
|*=||Multiply and Assign|
|⁄=||Divide and Assign|
|%=||Modulus and Assign|
|<<=||Left Shift by Value (Bitwise)|
|>>=||Right Shift by Value (Bitwise)|
|&=||And by Value (Bitwise)|
|^=||XOR by Value (Bitwise)|
||=||Or by Value (Bitwise)|
Created: May 13, 2005