圆括号运算符 ( )
用于控制表达式中的运算优先级。
这些交互的事例资源都是基于Github的仓库.如果你想提交更多的交互事例,请克隆这个urlhttps://github.com/mdn/interactive-examples 并且向我们发送合并请求。
语法
译者:下列语法是 MDN 上已知的最简单的之一。
( )
说明
圆括号运算符由一对圆括号组成,包裹表达式和子表达式用来覆盖常规的运算符优先级,达到低优先级的表达式比高优先级的表达式更早运算。
示例
下面的代码展示了加法运算先于乘法运算的情况。
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
规范
Specification | Status | Comment |
---|---|---|
ECMAScript Latest Draft (ECMA-262) The Grouping Operator |
Draft | |
ECMAScript 2015 (6th Edition, ECMA-262) The Grouping Operator |
Standard | |
ECMAScript 5.1 (ECMA-262) The Grouping Operator |
Standard | |
ECMAScript 1st Edition (ECMA-262) The Grouping Operator |
Standard | 初始化定义.在JavaScript1.0中生效 |
浏览器兼容性
本页的浏览器兼容性表都是基于结构数据,如果你想更新数据.可以查看
https://github.com/mdn/browser-compat-data 并且请给我们发送合并请求.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Grouping operator () |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support