diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/javascript/reference/operators/operator_precedence | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/pt-br/web/javascript/reference/operators/operator_precedence')
-rw-r--r-- | files/pt-br/web/javascript/reference/operators/operator_precedence/index.html | 343 |
1 files changed, 343 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/operators/operator_precedence/index.html b/files/pt-br/web/javascript/reference/operators/operator_precedence/index.html new file mode 100644 index 0000000000..474dd3e536 --- /dev/null +++ b/files/pt-br/web/javascript/reference/operators/operator_precedence/index.html @@ -0,0 +1,343 @@ +--- +title: Precedência de Operadores +slug: Web/JavaScript/Reference/Operators/Operator_Precedence +tags: + - JavaScript + - precedência de operadores +translation_of: Web/JavaScript/Reference/Operators/Operator_Precedence +--- +<div> +<div>{{jsSidebar("Operators")}}</div> +</div> + +<h2 id="Resumo">Resumo</h2> + +<p><span class="seoSummary">A precedência de operadores determina a ordem em que os operadores são processados. Operadores com maior precedência são processados primeiro.</span></p> + +<p>Um exe<span style="line-height: 1.5;">mplo simples:</span></p> + +<pre>3 + 4 * 5 // returns 23 +</pre> + +<p>O operador de multiplicação ("<code>*</code>") tem maior precedência que o operador de adição ("<code>+</code>") e por isso será executado primeiro.</p> + +<h2 id="Associativity" name="Associativity">Associatividade</h2> + +<p>Associatividade determina a ordem em que operadores da mesma precedência são processados. Por exemplo, considere a expressão:</p> + +<pre>a OP b OP c +</pre> + +<p>Associatividade à esquerda (esquerda para direita) significa que a expressão será processada como <code>(a OP b) OP c</code>, enquanto associatividade à direita (direita para esquerda) significa que será interpretada como <code>a OP (b OP c)</code>. Operadores de atribuição são associativos à direita, então você pode escrever:</p> + +<pre>a = b = 5; 5 = b = a +</pre> + +<p>com o resultado esperado que <code>a</code> e <code>b</code> tenham o valor 5. Isto é porque o operador de atribuição retorna o valor que ele atribuiu. Primeiro, <code>b</code> é definido com o valor 5. Então <code>a</code> é definido com o valor de <code>b</code>.</p> + +<h2 id="Table" name="Table">Tabela</h2> + +<p>A tabela seguinte está ordenada da mais alta (20) para a mais baixa (0) precedência.</p> + +<table class="fullwidth-table"> + <tbody> + <tr> + <th>Precedência</th> + <th>Tipo do Operador</th> + <th>Associatividade</th> + <th>Operadores individuais</th> + </tr> + <tr> + <td>20</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Grouping">Agrupamento</a></td> + <td>n/a</td> + <td><code>( … )</code></td> + </tr> + <tr> + <td rowspan="3">19</td> + <td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Dot_notation">Acesso a Membro</a></td> + <td>esquerda para direita</td> + <td><code>… . …</code></td> + </tr> + <tr> + <td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Dot_notation">Acesso a Membro Computado</a></td> + <td>esquerda para direita</td> + <td><code>… [ … ]</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/JavaScript/Reference/Operators/Special/new" title="JavaScript/Reference/Operators/Special_Operators/new_Operator">new</a> (com lista de argumentos)</td> + <td>n/a</td> + <td><code>new … ( … )</code></td> + </tr> + <tr> + <td rowspan="2">18</td> + <td><a href="/en-US/docs/Web/JavaScript/Guide/Functions" title="JavaScript/Reference/Operators/Special_Operators/function_call">Chamada a Função</a></td> + <td>esquerda para direita</td> + <td><code>… ( <var>… </var>)</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new" title="JavaScript/Reference/Operators/Special_Operators/new_Operator">new</a> (sem lista de argumentos)</td> + <td>direita para esquerda</td> + <td><code>new …</code></td> + </tr> + <tr> + <td rowspan="2">17</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment" title="JavaScript/Reference/Operators/Arithmetic_Operators">Incremento Pós-fixado</a></td> + <td>n/a</td> + <td><code>… ++</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement" title="JavaScript/Reference/Operators/Arithmetic_Operators">Decremento Pós-fixado</a></td> + <td>n/a</td> + <td><code>… --</code></td> + </tr> + <tr> + <td rowspan="9">16</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_NOT" title="JavaScript/Reference/Operators/Logical_Operators">NÃO lógico</a></td> + <td>direita para esquerda</td> + <td><code>! …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT" title="JavaScript/Reference/Operators/Bitwise_Operators">NÃO bit-a-bit</a></td> + <td>direita para esquerda</td> + <td><code>~ …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus" title="JavaScript/Reference/Operators/Arithmetic_Operators">Positivo Unário</a></td> + <td>direita para esquerda</td> + <td><code>+ …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_negation" title="JavaScript/Reference/Operators/Arithmetic_Operators">Negativo Unário</a></td> + <td>direita para esquerda</td> + <td><code>- …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment" title="JavaScript/Reference/Operators/Arithmetic_Operators">Incremento Pré-fixado</a></td> + <td>direita para esquerda</td> + <td><code>++ …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement" title="JavaScript/Reference/Operators/Arithmetic_Operators">Decremento Pré-fixado</a></td> + <td>direita para esquerda</td> + <td><code>-- …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof" title="JavaScript/Reference/Operators/Special_Operators/typeof_Operator">typeof</a></td> + <td>direita para esquerda</td> + <td><code>typeof …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/void" title="JavaScript/Reference/Operators/Special_Operators/void_Operator">void</a></td> + <td>direita para esquerda</td> + <td><code>void …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete" title="JavaScript/Reference/Operators/Special_Operators/delete_Operator">delete</a></td> + <td>direita para esquerda</td> + <td><code>delete …</code></td> + </tr> + <tr> + <td>15</td> + <td> + <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation">Exponenciação</a></p> + </td> + <td>direita para esquerda</td> + <td>… ** …</td> + </tr> + <tr> + <td rowspan="3">14</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Multiplication" title="JavaScript/Reference/Operators/Arithmetic_Operators">Multiplicação</a></td> + <td>esquerda para direita</td> + <td><code>… * …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Division" title="JavaScript/Reference/Operators/Arithmetic_Operators">Divisão</a></td> + <td>esquerda para direita</td> + <td><code>… / …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder" title="JavaScript/Reference/Operators/Arithmetic_Operators">Resto</a></td> + <td>esquerda para direita</td> + <td><code>… % …</code></td> + </tr> + <tr> + <td rowspan="2">13</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition" title="JavaScript/Reference/Operators/Arithmetic_Operators">Adição</a></td> + <td>esquerda para direita</td> + <td><code>… + …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Subtraction" title="JavaScript/Reference/Operators/Arithmetic_Operators">Subtração</a></td> + <td>esquerda para direita</td> + <td><code>… - …</code></td> + </tr> + <tr> + <td rowspan="3">12</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" title="JavaScript/Reference/Operators/Bitwise_Operators">Deslocamento de bits para esquerda</a></td> + <td>esquerda para direita</td> + <td><code>… << …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" title="JavaScript/Reference/Operators/Bitwise_Operators">Deslocamento de bits para direita</a></td> + <td>esquerda para direita</td> + <td><code>… >> …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" title="JavaScript/Reference/Operators/Bitwise_Operators">Deslocamento de bits para direita, sem sinal</a></td> + <td>esquerda para direita</td> + <td><code>… >>> …</code></td> + </tr> + <tr> + <td rowspan="6">11</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_operator" title="JavaScript/Reference/Operators/Comparison_Operators">Menor Que</a></td> + <td>esquerda para direita</td> + <td><code>… < …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than__or_equal_operator" title="JavaScript/Reference/Operators/Comparison_Operators">Menor ou Igual a</a></td> + <td>esquerda para direita</td> + <td><code>… <= …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator" title="JavaScript/Reference/Operators/Comparison_Operators">Maior Que</a></td> + <td>esquerda para direita</td> + <td><code>… > …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_or_equal_operator" title="JavaScript/Reference/Operators/Comparison_Operators">Maior ou Igual a</a></td> + <td>esquerda para direita</td> + <td><code>… >= …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/in" title="JavaScript/Reference/Operators/Special_Operators/in_Operator">in</a></td> + <td>esquerda para direita</td> + <td><code>… in …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/instanceof" title="JavaScript/Reference/Operators/Special_Operators/instanceof_Operator">instanceof</a></td> + <td>esquerda para direita</td> + <td><code>… instanceof …</code></td> + </tr> + <tr> + <td rowspan="4">10</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality" title="JavaScript/Reference/Operators/Comparison_Operators">Igualdade</a></td> + <td>esquerda para direita</td> + <td><code>… == …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Inequality" title="JavaScript/Reference/Operators/Comparison_Operators">Desigualdade</a></td> + <td>esquerda para direita</td> + <td><code>… != …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity" title="JavaScript/Reference/Operators/Comparison_Operators">Igualdade Estrita</a></td> + <td>esquerda para direita</td> + <td><code>… === …</code></td> + </tr> + <tr> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Nonidentity" title="JavaScript/Reference/Operators/Comparison_Operators">Desigualdade Estrita</a></td> + <td>esquerda para direita</td> + <td><code>… !== …</code></td> + </tr> + <tr> + <td>9</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_AND" title="JavaScript/Reference/Operators/Bitwise_Operators">E bit-a-bit</a></td> + <td>esquerda para direita</td> + <td><code>… & …</code></td> + </tr> + <tr> + <td>8</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR" title="JavaScript/Reference/Operators/Bitwise_Operators">OU exclusivo bit-a-bit</a></td> + <td>esquerda para direita</td> + <td><code>… ^ …</code></td> + </tr> + <tr> + <td>7</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR" title="JavaScript/Reference/Operators/Bitwise_Operators">OU bit-a-bit</a></td> + <td>esquerda para direita</td> + <td><code>… | …</code></td> + </tr> + <tr> + <td>6</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_AND" title="JavaScript/Reference/Operators/Logical_Operators">E lógico</a></td> + <td>esquerda para direita</td> + <td><code>… && …</code></td> + </tr> + <tr> + <td>5</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR" title="JavaScript/Reference/Operators/Logical_Operators">OU lógico</a></td> + <td>esquerda para direita</td> + <td><code>… || …</code></td> + </tr> + <tr> + <td>4</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator" title="JavaScript/Reference/Operators/Special_Operators/Conditional_Operator">Condicional</a></td> + <td>direita para esquerda</td> + <td><code>… ? … : …</code></td> + </tr> + <tr> + <td rowspan="12">3</td> + <td rowspan="12"><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators" title="JavaScript/Reference/Operators/Assignment_Operators">Atribuição</a></td> + <td rowspan="12">direita para esquerda</td> + <td><code>… = …</code></td> + </tr> + <tr> + <td><code>… += …</code></td> + </tr> + <tr> + <td><code>… -= …</code></td> + </tr> + <tr> + <td><code>… *= …</code></td> + </tr> + <tr> + <td><code>… /= …</code></td> + </tr> + <tr> + <td><code>… %= …</code></td> + </tr> + <tr> + <td><code>… <<= …</code></td> + </tr> + <tr> + <td><code>… >>= …</code></td> + </tr> + <tr> + <td><code>… >>>= …</code></td> + </tr> + <tr> + <td><code>… &= …</code></td> + </tr> + <tr> + <td><code>… ^= …</code></td> + </tr> + <tr> + <td><code>… |= …</code></td> + </tr> + <tr> + <td rowspan="2">2</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/yield" title="JavaScript/Reference/Operators/yield">yield</a></td> + <td rowspan="2">direita para esquerda</td> + <td><code>yield …</code></td> + </tr> + <tr> + <td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield*">yield*</a></td> + <td><code>yield* …</code></td> + </tr> + <tr> + <td>1</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator" title="JavaScript/Reference/Operators/Spread_operator">Propagação</a></td> + <td>n/a</td> + <td><code>...</code> …</td> + </tr> + <tr> + <td>0</td> + <td><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator" title="JavaScript/Reference/Operators/Comma_Operator">Vírgula / Sequência</a></td> + <td>esquerda para direita</td> + <td><code>… , …</code></td> + </tr> + </tbody> +</table> + +<p> </p> |