📅  最后修改于: 2020-10-23 14:20:26             🧑  作者: Mango
JavaScript运算符符是用于对操作数执行操作的符号。例如:
var sum=10+20;
在这里,+是算术运算运算符,=是赋值运算符。
JavaScript中有以下类型的运算符。
算术运算运算符用于对操作数执行算术运算。以下运算符称为JavaScript算术运算运算符。
Operator | Description | Example |
---|---|---|
+ | Addition | 10+20 = 30 |
– | Subtraction | 20-10 = 10 |
* | Multiplication | 10*20 = 200 |
/ | Division | 20/10 = 2 |
% | Modulus (Remainder) | 20%10 = 0 |
++ | Increment | var a=10; a++; Now a = 11 |
— | Decrement | var a=10; a–; Now a = 9 |
JavaScript的比较运算符的两个操作数进行比较。运算符如下:
Operator | Description | Example |
---|---|---|
== | Is equal to | 10==20 = false |
=== | Identical (equal and of same type) | 10==20 = false |
!= | Not equal to | 10!=20 = true |
!== | Not Identical | 20!==20 = false |
> | Greater than | 20>10 = true |
>= | Greater than or equal to | 20>=10 = true |
< | Less than | 20<10 = false |
<= | Less than or equal to | 20<=10 = false |
按位运算运算符对操作数执行按位运算。按位运算运算符如下:
Operator | Description | Example |
---|---|---|
& | Bitwise AND | (10==20 & 20==33) = false |
| | Bitwise OR | (10==20 | 20==33) = false |
^ | Bitwise XOR | (10==20 ^ 20==33) = false |
~ | Bitwise NOT | (~10) = -10 |
<< | Bitwise Left Shift | (10<<2) = 40 |
>> | Bitwise Right Shift | (10>>2) = 2 |
>>> | Bitwise Right Shift with Zero | (10>>>2) = 2 |
以下运算符称为JavaScript逻辑运算符。
Operator | Description | Example |
---|---|---|
&& | Logical AND | (10==20 && 20==33) = false |
|| | Logical OR | (10==20 || 20==33) = false |
! | Logical Not | !(10==20) = true |
以下运算符称为JavaScript赋值运算符。
Operator | Description | Example |
---|---|---|
= | Assign | 10+10 = 20 |
+= | Add and assign | var a=10; a+=20; Now a = 30 |
-= | Subtract and assign | var a=20; a-=10; Now a = 10 |
*= | Multiply and assign | var a=10; a*=20; Now a = 200 |
/= | Divide and assign | var a=10; a/=2; Now a = 5 |
%= | Modulus and assign | var a=10; a%=2; Now a = 0 |
以下运算符被称为JavaScript特殊运算符。
Operator | Description |
---|---|
(?:) | Conditional Operator returns value based on the condition. It is like if-else. |
, | Comma Operator allows multiple expressions to be evaluated as single statement. |
delete | Delete Operator deletes a property from the object. |
in | In Operator checks if object has the given property |
instanceof | checks if the object is an instance of given type |
new | creates an instance (object) |
typeof | checks the type of object. |
void | it discards the expression’s return value. |
yield | checks what is returned in a generator by the generator’s iterator. |