该章节说明了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
- 展开运算符可以将一个可迭代的对象在函数调用的位置展开成为多个参数,或者在数组字面量中展开成多个数组元素。
自增和自减
前置/后置自增运算符和前置/后置自减运算符.
一元运算符
一元运算符只有一个操作数.
-
delete
-
delete
运算符用来删除对象的属性. -
void
-
void
运算符表示表达式放弃返回值. -
typeof
-
typeof
运算符用来判断给定对象的类型. -
+
- 一元加运算符将操作转换为Number类型.
-
-
- 一元减运算符将操作转换为Number类型并取反.
-
~
- 按位非运算符.
-
!
- 逻辑非运算符.
算术运算符
算术运算符以二个数值(字面量或变量)作为操作数,并返回单个数值。
关系运算符
比较运算符比较二个操作数并返回基于比较结果的Boolean
值。
-
in
-
in运算符用来判断对象是否拥有给定属性
. -
instanceof
-
instanceof
运算符判断一个对象是否是另一个对象的实例. -
<
- 小于运算符
-
>
- 大于运算符.
-
<=
- 小于等于运算符.
-
>=
- 大于等于运算符。
注意: => 不是运算符,而是
箭头函数
的表示符。
相等运算符
如果相等,操作符返回的是Boolean(布尔)类型的true,否则是false。
位移运算符
在二进制的基础上对数字进行移动操作
二进制位运算符
二进制运算符将它们的操作数作为32个二进制位(0或1)的集合,并返回标准的JavaScript数值。
二元逻辑运算符
逻辑运算符典型的用法是用于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 |
浏览器兼容
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out
https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Array comprehensions | Chrome No support No | Edge No support No | Firefox No support 30 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 30 — 58 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
async function expression |
Chrome Full support 55 | Edge Full support 15 | Firefox Full support 52 | IE No support No | Opera Full support 42 | Safari Full support 10.1 | WebView Android Full support 55 | Chrome Android Full support 55 | Firefox Android Full support 52 | Opera Android Full support 42 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 6.0 | nodejs Full support 7.6.0
|
await |
Chrome Full support 55 | Edge Full support 14 | Firefox Full support 52 | IE No support No | Opera Full support 42 | Safari Full support 10.1 | WebView Android Full support 55 | Chrome Android Full support 55 | Firefox Android Full support 52 | Opera Android Full support 42 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 6.0 | nodejs Full support 7.6.0
|
class |
Chrome Full support 42 | Edge Full support 13 | Firefox Full support 45 | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 42 | Chrome Android Full support 42 | Firefox Android Full support 45 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 4.0 | nodejs Full support 6.0.0
|
Comma 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 |
Conditional operator (c ? t : f ) |
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 |
delete |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | 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 |
Destructuring assignment | Chrome Full support 49 | Edge Full support 14 | Firefox Full support 41
|
IE No support No | Opera Full support Yes | Safari Full support 8 | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 41
|
Opera Android Full support Yes | Safari iOS Full support 8 | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0 |
Expression closures | Chrome No support No | Edge No support No | Firefox No support 3 — 60 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 4 — 60 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
function |
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 |
function* |
Chrome Full support 49 | Edge Full support 12 | Firefox Full support 26 | IE No support No | Opera Full support 36 | Safari Full support 10 | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 26 | Opera Android Full support 36 | Safari iOS Full support 10 | Samsung Internet Android Full support 5.0 | nodejs Full support Yes |
Generator comprehensions | Chrome No support No | Edge No support No | Firefox No support 30 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 30 — 58 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
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 |
in |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | 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 |
instanceof |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5 | 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 |
Legacy generator function | Chrome No support No | Edge No support No | Firefox No support 2 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 4 — 58 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
new |
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 |
new.target |
Chrome Full support 46 | Edge Full support 13 | Firefox Full support 41 | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 46 | Chrome Android Full support 46 | Firefox Android Full support 41 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 5.0 | nodejs Full support 5.0.0 |
Nullish coalescing operator (?? )
|
Chrome No support No | Edge No support No | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
Object initializer | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 1 | Opera Full support Yes | Safari Full support 1 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support 1 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Optional chaining operator (?. )
|
Chrome Full support 79
|
Edge No support No | Firefox No support No | IE No support No | Opera Full support 65
|
Safari No support No | WebView Android No support No | Chrome Android Full support 79
|
Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
Pipeline operator (|> )
|
Chrome No support No | Edge No support No | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
Property accessors | 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 |
super |
Chrome Full support 42 | Edge Full support 13 | Firefox Full support 45 | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 42 | Chrome Android Full support 42 | Firefox Android Full support 45 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 4.0 | nodejs Full support Yes |
this |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | 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 |
typeof |
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 |
void |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5 | 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 |
yield |
Chrome Full support 39 | Edge Full support 12 | Firefox Full support 26
|
IE No support No | Opera Full support Yes | Safari Full support 10 | WebView Android Full support 39 | Chrome Android Full support 39 | Firefox Android Full support 26
|
Opera Android Full support Yes | Safari iOS Full support 10 | Samsung Internet Android Full support 4.0 | nodejs Full support 4.0.0
|
yield* |
Chrome Full support 39 | Edge Full support 12 | Firefox Full support 27
|
IE No support No | Opera Full support 26 | Safari Full support 10 | WebView Android Full support 39 | Chrome Android Full support 39 | Firefox Android Full support 27
|
Opera Android Full support 26 | Safari iOS Full support 10 | Samsung Internet Android Full support 4.0 | nodejs Full support 4.0.0
|
Legend
- Full support
- Full support
- No support
- No support
- 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.