aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/grouping/index.html
blob: 837cdf366fc3e24ead399cc3ee8402b1e8c4adcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: 圆括号运算符
slug: Web/JavaScript/Reference/Operators/Grouping
tags:
  - JavaScript
  - Operator
  - 操作符
translation_of: Web/JavaScript/Reference/Operators/Grouping
---
<div>{{jsSidebar("Operators")}}</div>

<p>圆括号运算符 <code>( )</code> 用于控制表达式中的运算优先级。</p>

<div>{{EmbedInteractiveExample("pages/js/expressions-groupingoperator.html")}}</div>

<p class="hidden">这些交互的事例资源都是基于Github的仓库.如果你想提交更多的交互事例,请克隆这个url<a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> 并且向我们发送合并请求。</p>

<h2 id="语法">语法</h2>

<p>译者:下列语法是 MDN 上已知的最简单的之一。</p>

<pre class="syntaxbox"> ( )</pre>

<h2 id="说明">说明</h2>

<p>圆括号运算符由一对圆括号组成,包裹表达式和子表达式用来覆盖常规的<a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">运算符优先级</a>,达到低优先级的表达式比高优先级的表达式更早运算。</p>

<h2 id="示例">示例</h2>

<p>下面的代码展示了加法运算先于乘法运算的情况。</p>

<pre class="brush:js">var a = 1;
var b = 2;
var c = 3;

// default precedence
a + b * c     // 7
// evaluated by default like this
a + (b * c)   // 7

// now overriding precedence
// addition before multiplication
(a + b) * c   // 9

// which is equivalent to
a * c + b * c // 9
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-grouping-operator', 'The Grouping Operator')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-grouping-operator', 'The Grouping Operator')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-11.1.6', 'The Grouping Operator')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES1', '#sec-11.1.4', 'The Grouping Operator')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>初始化定义.在JavaScript1.0中生效</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div class="hidden">本页的浏览器兼容性表都是基于结构数据,如果你想更新数据.可以查看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并且请给我们发送合并请求.</div>

<p>{{Compat("javascript.operators.grouping")}}</p>

<h2 id="See_also" name="See_also">相关链接</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">运算符优先级</a></li>
 <li>{{jsxref("Operators/delete", "delete")}}</li>
 <li>{{jsxref("Operators/typeof", "typeof")}}</li>
</ul>