该章节说明了JavaScript语言所有的运算符,表达式和关键字。

表达式和运算符分类

左侧工具栏是按字母表排序的列表。

主要表达式

JavaScript中基本关键字和常用表达式。

this
this 关键字指向函数的执行上下文。
function
function 关键字定义了函数表达式。
class
class 关键字定义了类表达式。
function*
function* 关键字定义了一个 generator 函数表达式。
yield
暂停和恢复 generator 函数。
yield*
委派给另外一个generator函数或可迭代的对象。
async function*
async function 定义一个异步函数表达式。
await
暂停或恢复执行异步函数,并等待promise的resolve/reject回调。
[]
数组初始化/字面量语法。
{}
对象初始化/字面量语法。
/ab+c/i
正则表达式字面量语法。
( )
分组操作符。

左表达式

左边的值是赋值的目标。

属性访问符
成员运算符提供了对对象的属性或方法的访问
(object.property 和 object["property"]).
new
new 运算符创建了构造函数实例。
new.target
在构造器中,new.target 指向new调用的构造器。
super
super 关键字调用父类的构造器.
...obj
展开运算符可以将一个可迭代的对象在函数调用的位置展开成为多个参数,或者在数组字面量中展开成多个数组元素。

自增和自减

前置/后置自增运算符和前置/后置自减运算符.

A++
后置自增运算符.
A--
后置自减运算符.
++A
前置自增运算符.
--A
前置自减运算符.

一元运算符

一元运算符只有一个操作数.

delete
delete 运算符用来删除对象的属性.
void
void 运算符表示表达式放弃返回值.
typeof
typeof 运算符用来判断给定对象的类型.
+
一元加运算符将操作转换为Number类型.
-
一元减运算符将操作转换为Number类型并取反.
~
按位非运算符.
!
逻辑非运算符.

算术运算符

算术运算符以二个数值(字面量或变量)作为操作数,并返回单个数值。

+
加法运算符.
-
减法运算符.
/
除法运算符.
*
乘法运算符.
%
取模运算符.

关系运算符

比较运算符比较二个操作数并返回基于比较结果的Boolean值。

in
in运算符用来判断对象是否拥有给定属性.
instanceof
instanceof 运算符判断一个对象是否是另一个对象的实例.
<
小于运算符
>
大于运算符.
<=
小于等于运算符.
>=
大于等于运算符。 
注意: => 不是运算符,而是箭头函数的表示符。

相等运算符

如果相等,操作符返回的是Boolean(布尔)类型的true,否则是false。

==
相等 运算符.
!=
不等 运算符.
===
全等 运算符.
!==
非全等 运算符.

位移运算符

在二进制的基础上对数字进行移动操作

<<
按位左移运算符。
>>
按位右移运算符。
>>>
按位无符号右移运算符。

二进制位运算符

二进制运算符将它们的操作数作为32个二进制位(0或1)的集合,并返回标准的JavaScript数值。

&
二进制位与(AND)。
|
二进制位或(OR)。
^
二进制位异或(XOR)。

二元逻辑运算符

逻辑运算符典型的用法是用于boolean(逻辑)值运算, 它们返回boolean值。

&&
逻辑与.
||
逻辑或.

条件(三元)运算符

(condition ? ifTrue : ifFalse)

条件元素运算符把两个结果中其中一个符合运算逻辑的值返回。

赋值运算符

赋值元素符会将右边的操作数的值分配给左边的操作数,并将其值修改为右边操作数相等的值。

=
赋值运算符。
*=
赋值乘积。
/=
赋值商。
%=
赋值求余。
+=
赋值求和。
-=
赋值求差。
<<=
左位移。
>>=
右位移。
>>>=
无符号右位移。
&=
赋值与。
^=
赋值按位异或。
|=
赋值或。
[a, b] = [1, 2]
{a, b} = {a:1, b:2}

解构赋值允许你分配数组或者对象变量的属性通过使用规定的语法,其看起来和数组和对象字面量很相似。

逗号操作符

,
逗号操作符允许在一个判断状态中有多个表达式去进行运算并且最后返回最后一个表达式的值。

非标准化特性

Legacy generator function
function关键字能用来定义表达式内部未执行完的function的余下功能。 为了能执行function内部余下的代码, 这个function的内部至少包含一个yield 表达式。
Expression closures
闭包表达式语法是一个缩写简单的函数。
[for (x of y) x]
数组解析
(for (x of y) y)
生成器解析

规范

Specification Status Comment
ECMAScript 1st Edition (ECMA-262)
Expressions
Standard Initial definition
ECMAScript 5.1 (ECMA-262)
Expressions
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
ECMAScript Language: Expressions
Standard New: Spread syntax, rest syntax, destructuring assignment, super keyword.
ECMAScript Latest Draft (ECMA-262)
ECMAScript Language: Expressions
Draft  

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Array comprehensions
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 30 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 30 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
async function expressionChrome Full support 55Edge Full support 15Firefox Full support 52IE No support NoOpera Full support 42Safari Full support 10.1WebView Android Full support 55Chrome Android Full support 55Edge Mobile Full support 15Firefox Android Full support 52Opera Android Full support 42Safari iOS Full support 10.1Samsung Internet Android Full support 6.0nodejs Full support 7.6.0
Full support 7.6.0
Full support 7.0.0
Disabled
Disabled From version 7.0.0: this feature is behind the --harmony runtime flag.
awaitChrome Full support 55Edge Full support YesFirefox Full support 52IE ? Opera Full support 42Safari Full support 10.1WebView Android Full support 55Chrome Android Full support 55Edge Mobile Full support YesFirefox Android Full support 52Opera Android Full support 42Safari iOS Full support 10.1Samsung Internet Android Full support 6.0nodejs Full support 7.6.0
Full support 7.6.0
Full support 7.0.0
Disabled
Disabled From version 7.0.0: this feature is behind the --harmony runtime flag.
classChrome Full support 42Edge Full support YesFirefox Full support 45IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 42Chrome Android Full support 42Edge Mobile Full support YesFirefox Android Full support 45Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 4.0nodejs Full support 6.0.0
Full support 6.0.0
Full support 5.0.0
Disabled
Disabled From version 5.0.0: this feature is behind the --harmony runtime flag.
Comma operatorChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support 3Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
Conditional operator (c ? t : f)Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
deleteChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
Destructuring assignmentChrome Full support 49Edge Full support 14Firefox Full support 41
Notes
Full support 41
Notes
Notes Firefox provided a non-standard destructuring implementation from Firefox 2 to 40.
IE No support NoOpera Full support YesSafari Full support 8WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 14Firefox Android Full support 41
Notes
Full support 41
Notes
Notes Firefox provided a non-standard destructuring implementation from Firefox 2 to 40.
Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support 5.0nodejs Full support 6.0.0
Expression closures
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 3 — 60IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 4 — 60Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
functionChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
function*Chrome Full support YesEdge Full support YesFirefox Full support 26IE No support NoOpera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 26Opera Android Full support YesSafari iOS Full support 10Samsung Internet Android Full support Yesnodejs Full support Yes
Generator comprehensions
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 30 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 30 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
Grouping operator ()Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
inChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
instanceofChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
Legacy generator function
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 2 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 4 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
newChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
new.targetChrome Full support 46Edge Full support YesFirefox Full support 41IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 41Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 5.0nodejs Full support 5.0.0
Object initializerChrome Full support 1Edge Full support YesFirefox Full support 1IE Full support 1Opera Full support YesSafari Full support 1WebView Android Full support 1Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support 1Samsung Internet Android Full support Yesnodejs Full support Yes
Pipeline operator (|>)
Experimental
Chrome No support NoEdge No support NoFirefox Full support 58
Disabled
Full support 58
Disabled
Disabled From version 58: this feature is behind the --enable-pipeline-operator compile flag.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 58
Disabled
Full support 58
Disabled
Disabled From version 58: this feature is behind the --enable-pipeline-operator compile flag.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
Property accessorsChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
superChrome Full support 42Edge Full support YesFirefox Full support 45IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 42Chrome Android Full support 42Edge Mobile Full support YesFirefox Android Full support 45Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 4.0nodejs Full support Yes
thisChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
typeofChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
voidChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
yieldChrome Full support 39Edge Full support YesFirefox Full support 26
Notes
Full support 26
Notes
Notes Starting with Firefox 33, the parsing of the yield expression has been updated to conform with the ES2015 specification.
IE No support NoOpera Full support YesSafari Full support 10WebView Android Full support 39Chrome Android Full support 39Edge Mobile Full support YesFirefox Android Full support 26
Notes
Full support 26
Notes
Notes Starting with Firefox 33, the parsing of the yield expression has been updated to conform with the ES2015 specification.
Opera Android Full support YesSafari iOS Full support 10Samsung Internet Android Full support 4.0nodejs Full support 4.0.0
Full support 4.0.0
Full support 0.12
Disabled
Disabled From version 0.12: this feature is behind the --harmony runtime flag.
yield*Chrome Full support YesEdge Full support YesFirefox Full support 27
Notes
Full support 27
Notes
Notes Starting with Firefox 33, the parsing of the yield expression has been updated to conform with the ES2015 specification.
IE No support NoOpera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 27
Notes
Full support 27
Notes
Notes Starting with Firefox 33, the parsing of the yield expression has been updated to conform with the ES2015 specification.
Opera Android Full support YesSafari iOS Full support 10Samsung Internet Android Full support Yesnodejs Full support 4.0.0
Full support 4.0.0
Full support 0.12
Disabled
Disabled From version 0.12: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

相关链接

文档标签和贡献者

标签: 
最后编辑者: zhangchen,