运算符

这篇翻译不完整。请帮忙从英语翻译这篇文章


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

表达式和运算符分类

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

主要表达式

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

this
this 关键字指向函数的执行上下文。
function
function 关键字定义了函数表达式。
class
class 关键字定义了类表达式。
function*
function* 关键字定义了一个 generator 函数表达式。
yield
暂停和恢复 generator 函数。
yield*
委派给另外一个generator函数或可迭代的对象。
[]
数组初始化/字面量语法。
{}
对象初始化/字面量语法。
/ab+c/i
正则表达式字面量语法。
[for (x of y) x]
Array comprehensions。
(for (x of y) y)
Generator comprehensions。
( )
圆括号操作符。

Left-hand-side expressions

Left values are the destination of an assignment.

Property accessors
成员访问可以访问对象的属性或方法
(object.property and object["property"]).
new
new 运算符创建了构造函数实例.
super
super 关键字调用父类的构造器.
...obj
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.

自增运算和自减运算

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

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

一元运算符

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

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

Arithmetic operators

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

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

关系运算符

A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

in
in运算符用来判断对象是否拥有给定属性.
instanceof
instanceof 运算符判断一个对象是否是另一个对象的实例.
<
小于运算符
>
大于运算符.
<=
小于等于运算符.
>=
大于等于运算符.

相等操作符

The result of evaluating an equality operator is always of type Boolean based on whether the comparison is true.

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

位移运算符

Operations to shift all bits of the operand.

<<
Bitwise left shift operator.
>>
Bitwise right shift operator.
>>>
Bitwise unsigned right shift operator.

二元按位运算符

Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

&
Bitwise AND.
|
Bitwise OR.
^
Bitwise XOR.

二元逻辑运算符

逻辑运算符是典型的使用boolean(逻辑)值, and when they are, they return a boolean value.

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

Conditional (ternary) operator

(condition ? ifTrue : ifFalse)

The conditional operator returns one of two values based on the logical value of the condition.

Assignment operators

An assignment operator assigns a value to its left operand based on the value of its right operand.

=
Assignment operator.
*=
Multiplication assignment.
/=
Division assignment.
%=
Remainder assignment.
+=
Addition assignment.
-=
Subtraction assignment
<<=
Left shift assignment.
>>=
Right shift assignment.
>>>=
Unsigned right shift assignment.
&=
Bitwise AND assignment.
^=
Bitwise XOR assignment.
|=
Bitwise OR assignment.
[a, b] = [1, 2]
{a, b} = {a:1, b:2}

Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

逗号操作符

,
The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.

非标准化特性

Legacy generator function
The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one yield expression.
Expression closures
The expression closure syntax is a shorthand for writing simple function.

规范

规范 状态 说明
ECMAScript 1st Edition. Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
Expressions
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
ECMAScript Language: Expressions
Standard New: Spread operator, destructuring assignment, super keyword, Array comprehensions, Generator comprehensions

相关链接

运算符优先级

文档标签和贡献者

标签: 
向此页面作出贡献: lunix01, Go7hic, yenshen, ziyunfei, teoli
最后编辑者: lunix01,
隐藏侧边栏