运算符

  • 版本网址缩略名: Core_JavaScript_1.5_Guide/运算符
  • 版本标题: 运算符
  • 版本 id: 255436
  • 创建于:
  • 创建者: Andyyard
  • 是否是当前版本?
  • 评论 New page: == 运算符 == JavaScript has the following types of operators. This section describes the operators and contains information about operator precedence. * [[Core JavaScript 1.5 Guide:Op...

修订内容

运算符

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.

运算符的优先级

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.

{{template.PreviousNext("Core_JavaScript_1.5_Guide:Expressions", "Core_JavaScript_1.5_Guide:Operators:Assignment_Operators")}}

--AndyYard 06:21 2007年11月11日 (PST)

{{ wiki.languages( { "es": "es/Gu\u00eda_JavaScript_1.5/Operadores", "fr": "fr/Guide_JavaScript_1.5/Op\u00e9rateurs", "ja": "ja/Core_JavaScript_1.5_Guide/Operators", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Operatory" } ) }}

修订版来源

<h3 name=".E8.BF.90.E7.AE.97.E7.AC.A6"> 运算符 </h3>
<p>JavaScript has the following types of operators. This section describes the operators and contains information about operator precedence.
</p>
<ul><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Assignment_Operators">Assignment Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Comparison_Operators">Comparison Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Arithmetic_Operators">Arithmetic Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Bitwise_Operators">Bitwise Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Logical_Operators">Logical Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/String_Operators">String Operators</a>
</li><li> <a href="cn/Core_JavaScript_1.5_Guide/Operators/Special_Operators">Special Operators</a>
</li></ul>
<p>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:
</p>
<pre>operand1 operator operand2
</pre>
<p>For example, <code>3+4</code> or <code>x*y</code>.
</p><p>A unary operator requires a single operand, either before or after the operator:
</p>
<pre>operator operand
</pre>
<p>or
</p>
<pre>operand operator
</pre>
<p>For example, <code>x++</code> or <code>++x</code>.
</p>
<h4 name=".E8.BF.90.E7.AE.97.E7.AC.A6.E7.9A.84.E4.BC.98.E5.85.88.E7.BA.A7"> 运算符的优先级 </h4>
<p><small><i>In accordance with <a href="Talk:cn/Core_JavaScript_1.5_Guide/Operators#Precedence_Table">relevant discussion</a>, this table was reversed to list operators in <b>decreasing</b> order of priority.</i></small>
</p>
<table class="fullwidth-table">
<tbody><tr>
<th>Operator type</th>
<th>Individual operators</th>
</tr>
<tr>
<td>member  </td>
<td>.  []</td>
</tr>
<tr>
<td>call / create instance  </td>
<td>()  new</td>
</tr>
<tr>
<td>negation/increment  </td>
<td>!  ~  -  +  ++  --  typeof  void  delete</td>
</tr>
<tr>
<td>multiply/divide  </td>
<td>*  /  %</td>
</tr>
<tr>
<td>addition/subtraction  </td>
<td>+  -</td>
</tr>
<tr>
<td>bitwise shift  </td>
<td>&lt;&lt;  &gt;&gt;  &gt;&gt;&gt;</td>
</tr>
<tr>
<td>relational  </td>
<td>&lt;  &lt;=  &gt;  &gt;=  in  instanceof</td>
</tr>
<tr>
<td>equality  </td>
<td>==  !=  ===  !==</td>
</tr>
<tr>
<td>bitwise-and  </td>
<td>&amp;</td>
</tr>
<tr>
<td>bitwise-xor  </td>
<td>^</td>
</tr>
<tr>
<td>bitwise-or  </td>
<td>|</td>
</tr>
<tr>
<td>logical-and  </td>
<td>&amp;&amp;</td>
</tr>
<tr>
<td>logical-or  </td>
<td>||</td>
</tr>
<tr>
<td>conditional  </td>
<td>?:</td>
</tr>
<tr>
<td>assignment  </td>
<td>=  +=   -=  *=  /=  %=  &lt;&lt;=  &gt;&gt;=  &gt;&gt;&gt;=  &amp;=  ^=  |=</td>
</tr>
<tr>
<td>comma</td>
<td>,</td>
</tr>
</tbody></table>
<p><small><b>Table 3.1: Operator precedence</b></small>
</p><p>A more detailed version of this table, complete with links to additional details about each operator, may be found in <a href="cn/Core_JavaScript_1.5_Reference/Operators/Operator_Precedence#Table">the Reference section</a>.
</p><p>{{template.PreviousNext("Core_JavaScript_1.5_Guide:Expressions", "Core_JavaScript_1.5_Guide:Operators:Assignment_Operators")}}
</p><p>--<a href="User:Andyyard">AndyYard</a> 06:21 2007年11月11日 (PST)
</p>{{ wiki.languages( { "es": "es/Gu\u00eda_JavaScript_1.5/Operadores", "fr": "fr/Guide_JavaScript_1.5/Op\u00e9rateurs", "ja": "ja/Core_JavaScript_1.5_Guide/Operators", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Operatory" } ) }}
恢复到这个版本