Operators
JavaScript has a full range of operators, including arithmetic, logic, bit assignment operator and, in addition there are other operators.
arithmetic:
description | symbol |
---|---|
Negative | - |
Increment | ++ |
Decreasing | – |
multiplication | * |
division | / |
Modulo operation | % |
addition | + |
Subtraction | - |
logic:
description | symbol |
---|---|
Logical NOT | ! |
Less than | < |
more than the | > |
Less than or equal | <= |
greater or equal to | >= |
equal | == |
not equal to | != |
Logic and | && |
Logical or | || |
Condition (ternary operator) | ?: |
comma | , |
Identity | === |
Nonidentical | !== |
Bit operation: bit arithmetic want to learn more , please click here to explain in detail
description | symbol |
---|---|
Bitwise | ~ |
Bitwise left shift | << |
Bitwise Right Shift | >> |
Unsigned right shift | >>> |
Bitwise AND | & |
Bitwise or | | |
Bitwise XOR | ^ |
Assignment:
description | symbol |
---|---|
Assignment | = |
Addition assignment | += |
Subtraction assignment | -= |
Multiplication assignment | *= |
Division assignment | /= |
Modulo assignment | %= |
Operator Precedence
JavaScript is in accordance with a specific operator in order of priority of the evaluation, in this order is the operator.
Here, I Low lists these operators, the operators in the same row from left to right evaluation order.
Operators | description |
---|---|
. [ ] () | Field access, array subscript and function calls |
++ – - ~ ! typeof new void delete | Unary operators, return data type, object creation, undefined values |
* / % | Multiplication, division, modulo |
+ - + | Addition, subtraction, string concatenation |
<< >> >>> | Displacement |
< <= > >= | Less than, less than or equal, greater than, greater than or equal |
== != === !== | Equal, not equal, identity, nonidentical |
& | Bitwise AND |
^ | Bitwise XOR |
| | Bitwise or |
&& | Logic and |
|| | Logical or |
?: | Condition (ternary operator) |
= | Assignment |
, | Multiple evaluation |
Having a higher priority operator to be evaluated before a lower priority operators, for example:
z = 78 * (96+3+45)
// 它们将这个顺序求值:(),*,+,+,=
Parentheses may be used to alter the order of evaluation, all of the expression in parentheses should be evaluated before the rest of the for statement.
Operation:
First evaluation of the expression in parentheses: wherein there are two operators addition, they have the same priority: 96 + 3 are added, and then added to the 45, 144 to give a result.
Multiplication is then: 78 and 144 multiplied by the result 11232.
Finally, the assignment operator: 11232 assigned to z.