Changes

JavaScript Operators

1,404 bytes removed, 13:37, 30 May 2007
no edit summary
</pre>
 
== Operator Precedence ==
 
When using expressions that containing a mixture of operators it is important to be aware that the expression is evaluated in a particular order depending on operator priority. This priority order is outlined in the following table which lists operators from highest priority to lowest:
 
<table border="1">
<tr>
<th>Operator<th>Description<th>Priority</th>
<tr>
<td>* / % <td>Multiplication, Division, Modulus<td>Highest</td>
<tr>
<td>+ - <td>Addition, Subtraction<td></td>
<tr>
<td><< >> >>><td>Bitwise Shift<td></td>
<tr>
<td>< <= > >=<td>Comparison<td></td>
<tr>
<td>== !=<td>Equality<td></td>
<tr>
<td>&&<td>Logical AND<td></td>
<tr>
<td>||<td>Logical OR<td></td>
<tr>
<td>?:<td>Conditional<td></td>
<tr>
<td>= += -= *= /= %=<td>Assignment<td></td>
<tr>
<td>,<td>Comma<td>Lowest</td>
<table>
 
Given the above table then clearly the following expression will multiply x by before adding the result to z because the multiplication operate has a higher precedence than the addition operator:
 
<pre>
 
k = z + x * y;
 
</pre>
 
The use of parentheses can be used to increase the precendence of part of an expression. For example if we put parentheses around the addition in the expression from above that part of the expression will be evaluated first. In the following example:
 
<pre>
 
k = (z + x) * y;
 
</pre>
 
z will be added to x and the result will then be multiplied by y.
== Operator Precedence ==