Visit Mozilla.org

Core JavaScript 1.5 Guide:Operators

From MDC


[edit] Operators

JavaScript has the following types of operators. This section describes the operators and contains information about operator precedence.

JavaScript has both binary and unary operators, and one special ternary operator, the conditional operator. A binary operator requires two operands, one before the operator and one after the operator:

operand1 operator operand2

For example, 3+4 or x*y.

A unary operator requires a single operand, either before or after the operator:

operator operand

or

operand operator

For example, x++ or ++x.

[edit] Operator Precedence

In accordance with relevant discussion, this table was reversed to list operators in decreasing order of priority.

Operator type Individual operators
member .  []
call / create instance ()  new
negation/increment !  ~  -  +  ++  --  typeof  void  delete
multiply/divide *  /  %
addition/subtraction +  -
bitwise shift <<  >>  >>>
relational <  <=  >  >=  in  instanceof
equality ==  !=  ===  !==
bitwise-and &
bitwise-xor ^
bitwise-or |
logical-and &&
logical-or ||
conditional ?:
assignment =  +=  -=  *=  /=  %=  <<=  >>=  >>>=  &=  ^=  |=
comma ,

Table 3.1: Operator precedence

A more detailed version of this table, complete with links to additional details about each operator, may be found in the Reference section.

« Previous Next »