mozilla

# Revision 503481 of Operator Precedence

• URL ревизии: Core_JavaScript_1.5_Reference/Statements/Приоритеты_операторов
• Заголовок ревизии: Operator Precedence
• ID ревизии: 503481
• Создано:
• Автор: ajaybhat
• Это текущая версия? Да
• комментировать
Метки:

## Содержание версии

### What is operator precedence?

Operator precedence determines the order in which the statements are executed. Operators with higher precedence are applied first.

A common example:

```3 + 4 * 5 // returns 23
```

The multiplication operator (" * ") has a higher precedence than the addition (" + ") and thus will be executed first.

Аssociativity

Associativity determines the order in which the operators with the same priority are processed. For example, consider the expression:

```a OP b OP c
```

Left associativity (left to right) means that it is treated as (A OP b) OP C , while the right associativity (left to right) means that it is interpreted as A OP (OP C b) . Operators designated as a right-associative, you can also write:

```a = b = 5;
```

with the expected result that a and b will have a value of 5. This is because the assignment operator returns the value that is assigned to him. Firstly, b is assigned to 5. Then a assigns the value b .

Table of Operator Priority

The following table is ordered from highest (1) to lowest (17) priority.

Priority Operator Type Associativity Individual Operators (Examples)
1 member left-to-right .
[]
new right-to-left new
2 function call left-to-right ()
3 increment n/a ++
decrement n/a --
4 logical-not right-to-left !
bitwise not right-to-left ~
unary + right-to-left +
unary negation right-to-left -
typeof right-to-left typeof
void right-to-left void
delete right-to-left delete
5 multiplication left-to-right *
division left-to-right /
modulus left-to-right %
subtraction left-to-right -
7 bitwise shift left-to-right <<
>>
>>>
8 relational left-to-right <
<=
>
>=
in left-to-right in
instanceof left-to-right instanceof
9 equality left-to-right ==
!=
===
!==
10 bitwise-and left-to-right &
11 bitwise-xor left-to-right ^
12 bitwise-or left-to-right |
13 logical-and left-to-right &&
14 logical-or left-to-right ||
15 conditional right-to-left ?:
16 yield right-to-left yield
17 assignment right-to-left =
+=
-=
*=
/=
%=
<<=
>>=
>>>=
&=
^=
|=
18 comma left-to-right ,

{{ languages( { "fr": "fr/Référence_de_JavaScript_1.5_Core/Opérateurs/Priorités_des_opérateurs", "ja": "ja/JavaScript/Reference/Operators/Operator_Precedence", "pl": "pl/Dokumentacja_języka_JavaScript_1.5/Operatory/Pierwszeństwo_operatorów" } ) }}

## Источник ревизии

```<h3 id="Summary" name="Summary">What is operator precedence?</h3>
<p>Operator precedence determines the order in which the statements are executed. Operators with higher precedence are applied first.</p>
<p>A common example:</p>
<pre class="eval">3 + 4 * 5 // returns 23	 <span style="font-size: 14px; line-height: 21px; white-space: normal;">
</span></pre>
<p>The multiplication operator (" * ") has a higher precedence than the addition (" + ") and thus will be executed first.</p>
<div>
<span style="font-size: 24px; letter-spacing: -0.5px; line-height: 24px;">Аssociativity</span></div>
<p>Associativity determines the order in which the operators with the same priority are processed. For example, consider the expression:</p>
<pre class="eval">a OP b OP c<span style="font-size: 14px; line-height: 21px; white-space: normal;">
</span></pre>
<p>Left associativity (left to right) means that it is treated as (A OP b) OP C , while the right associativity (left to right) means that it is interpreted as A OP (OP C b) . Operators designated as a right-associative, you can also write:</p>
<pre class="eval">a = b = 5;<span style="font-size: 14px; line-height: 21px; white-space: normal;">
</span></pre>
<p>with the expected result that a and b will have a value of 5. This is because the assignment operator returns the value that is assigned to him. Firstly, b is assigned to 5. Then a assigns the value b .</p>
<div>
<span style="font-size: 24px; letter-spacing: -0.5px; line-height: 24px;">Table of Operator Priority</span></div>
<div>
</div>
<p>The following table is ordered from highest (1) to lowest (17) priority.</p>
<div>
</div>
<table class="fullwidth-table">
<tbody>
<tr>
<th>Priority</th>
<th>Operator Type</th>
<th>Associativity</th>
<th>Individual Operators (Examples)</th>
</tr>
<tr>
<td rowspan="3">1</td>
<td rowspan="2"><a href="/en/JavaScript/Reference/Operators/Member_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Member_Operators">member</a></td>
<td rowspan="2">left-to-right</td>
<td>.</td>
</tr>
<tr>
<td>[]</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/new" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/new_Operator">new</a></td>
<td>right-to-left</td>
<td>new</td>
</tr>
<tr>
<td>2</td>
<td><a href="/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/function_call" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/function_call">function call</a></td>
<td>left-to-right</td>
<td>()</td>
</tr>
<tr>
<td rowspan="2">3</td>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">increment</a></td>
<td>n/a</td>
<td>++</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">decrement</a></td>
<td>n/a</td>
<td>--</td>
</tr>
<tr>
<td rowspan="7">4</td>
<td><a href="/en/JavaScript/Reference/Operators/Logical_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Logical_Operators">logical-not</a></td>
<td>right-to-left</td>
<td>!</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Bitwise_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators">bitwise not</a></td>
<td>right-to-left</td>
<td>~</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">unary +</a></td>
<td>right-to-left</td>
<td>+</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">unary negation</a></td>
<td>right-to-left</td>
<td>-</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/typeof" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/typeof_Operator">typeof</a></td>
<td>right-to-left</td>
<td>typeof</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/void" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/void_Operator">void</a></td>
<td>right-to-left</td>
<td>void</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/delete" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/delete_Operator">delete</a></td>
<td>right-to-left</td>
<td>delete</td>
</tr>
<tr>
<td rowspan="3">5</td>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">multiplication</a></td>
<td>left-to-right</td>
<td>*</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">division</a></td>
<td>left-to-right</td>
<td>/</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">modulus</a></td>
<td>left-to-right</td>
<td>%</td>
</tr>
<tr>
<td rowspan="2">6</td>
<td>left-to-right</td>
<td>+</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Arithmetic_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Arithmetic_Operators">subtraction</a></td>
<td>left-to-right</td>
<td>-</td>
</tr>
<tr>
<td rowspan="3">7</td>
<td rowspan="3"><a href="/en/JavaScript/Reference/Operators/Bitwise_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators">bitwise shift</a></td>
<td rowspan="3">left-to-right</td>
<td>&lt;&lt;</td>
</tr>
<tr>
<td>&gt;&gt;</td>
</tr>
<tr>
<td>&gt;&gt;&gt;</td>
</tr>
<tr>
<td rowspan="6">8</td>
<td rowspan="4"><a href="/en/JavaScript/Reference/Operators/Comparison_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Comparison_Operators">relational</a></td>
<td rowspan="4">left-to-right</td>
<td>&lt;</td>
</tr>
<tr>
<td>&lt;=</td>
</tr>
<tr>
<td>&gt;</td>
</tr>
<tr>
<td>&gt;=</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/in" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/in_Operator">in</a></td>
<td>left-to-right</td>
<td>in</td>
</tr>
<tr>
<td><a href="/en/JavaScript/Reference/Operators/Special/instanceof" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/instanceof_Operator">instanceof</a></td>
<td>left-to-right</td>
<td>instanceof</td>
</tr>
<tr>
<td rowspan="4">9</td>
<td rowspan="4"><a href="/en/JavaScript/Reference/Operators/Comparison_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Comparison_Operators">equality</a></td>
<td rowspan="4">left-to-right</td>
<td>==</td>
</tr>
<tr>
<td>!=</td>
</tr>
<tr>
<td>===</td>
</tr>
<tr>
<td>!==</td>
</tr>
<tr>
<td>10</td>
<td><a href="/en/JavaScript/Reference/Operators/Bitwise_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators">bitwise-and</a></td>
<td>left-to-right</td>
<td>&amp;</td>
</tr>
<tr>
<td>11</td>
<td><a href="/en/JavaScript/Reference/Operators/Bitwise_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators">bitwise-xor</a></td>
<td>left-to-right</td>
<td>^</td>
</tr>
<tr>
<td>12</td>
<td><a href="/en/JavaScript/Reference/Operators/Bitwise_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators">bitwise-or</a></td>
<td>left-to-right</td>
<td>|</td>
</tr>
<tr>
<td>13</td>
<td><a href="/en/JavaScript/Reference/Operators/Logical_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Logical_Operators">logical-and</a></td>
<td>left-to-right</td>
<td>&amp;&amp;</td>
</tr>
<tr>
<td>14</td>
<td><a href="/en/JavaScript/Reference/Operators/Logical_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Logical_Operators">logical-or</a></td>
<td>left-to-right</td>
<td>||</td>
</tr>
<tr>
<td>15</td>
<td><a href="/en/JavaScript/Reference/Operators/Special/Conditional_Operator" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Conditional_Operator">conditional</a></td>
<td>right-to-left</td>
<td>?:</td>
</tr>
<tr>
<td>16</td>
<td><a href="/en-US/docs/JavaScript/Reference/Operators/yield" title="en-US/docs/JavaScript/Reference/Operators/yield">yield</a></td>
<td>right-to-left</td>
<td>yield</td>
</tr>
<tr>
<td rowspan="12">17</td>
<td rowspan="12"><a href="/en/JavaScript/Reference/Operators/Assignment_Operators" title="en/Core_JavaScript_1.5_Reference/Operators/Assignment_Operators">assignment</a></td>
<td rowspan="12">right-to-left</td>
<td>=</td>
</tr>
<tr>
<td>+=</td>
</tr>
<tr>
<td>-=</td>
</tr>
<tr>
<td>*=</td>
</tr>
<tr>
<td>/=</td>
</tr>
<tr>
<td>%=</td>
</tr>
<tr>
<td>&lt;&lt;=</td>
</tr>
<tr>
<td>&gt;&gt;=</td>
</tr>
<tr>
<td>&gt;&gt;&gt;=</td>
</tr>
<tr>
<td>&amp;=</td>
</tr>
<tr>
<td>^=</td>
</tr>
<tr>
<td>|=</td>
</tr>
<tr>
<td>18</td>
<td><a href="/en/JavaScript/Reference/Operators/Special/Comma_Operator" title="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Comma_Operator">comma</a></td>
<td>left-to-right</td>
<td>,</td>
</tr>
</tbody>
</table>
<p>{{ languages( { "fr": "fr/Référence_de_JavaScript_1.5_Core/Opérateurs/Priorités_des_opérateurs", "ja": "ja/JavaScript/Reference/Operators/Operator_Precedence", "pl": "pl/Dokumentacja_języka_JavaScript_1.5/Operatory/Pierwszeństwo_operatorów" } ) }}</p>
<div id="cke_pastebin" style="position: absolute; top: 966px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
</div>```