1.Assignment operators(分配操作)
Name | Shorthand operator | Meaning |
---|---|---|
Assignment | x = y | x = y |
Addition assignment | x += y | x = x + y |
Subtraction assignment | x -= y | x = x - y |
Multiplication assignment | x *= y | x = x * y |
Division assignment | x /= y | x = x / y |
Remainder assignment | x %= y | x = x % y |
Exponentiation assignment | x **= y | x = x ** y |
Left shift assignment | x <<= y | x = x << y |
Right shift assignment | x >>= y | x = x >> y |
Unsigned right shift assignment | x >>>= y | x = x >>> y |
Bitwise AND assignment | x &= y | x = x & y |
Bitwise XOR assignment | x ^= y | x = x ^ y |
Bitwise OR assignment | x |= y |
x = x | y |
2.Comparison operators(比较运算符)
Operator | Description | Examples returning true |
---|---|---|
Equal (==) | Returns true if the operands are equal. | 3 == var1 ; "3" == var1; 3 == '3' |
Not equal (!=) | Returns true if the operands are not equal. | var1 != 4 var2 != "3" |
Strict equal (===) | Returns true if the operands are equal and of the same type. See also Object.is and sameness in JS. | 3 === var1 |
Strict not equal (!==) | Returns true if the operands are of the same type but not equal, or are of different type. | var1 !== "3" ;3 !== '3' |
Greater than (>) | Returns true if the left operand is greater than the right operand. | var2 > var1; "12" > 2 |
Greater than or equal (>=) | Returns true if the left operand is greater than or equal to the right operand. | var2 >= var1 var1 >= 3` |
Less than (<) | Returns true if the left operand is less than the right operand. | var1 < var2 "2" < 12 |
Less than or equal (<=) | Returns true if the left operand is less than or equal to the right operand. | var1 <= var2 var2 <= 5 |
3.Arithmetic operators
Operator | Description | Example |
---|---|---|
Remainder (%) | Binary operator. Returns the integer remainder of dividing the two operands. | 12 % 5 returns 2. |
Increment (++) | Unary operator. Adds one to its operand. If used as a prefix operator (++x), returns the value of its operand after adding one; if used as a postfix operator (x++), returns the value of its operand before adding one. | If x is 3, then ++x sets x to 4 and returns 4, whereas x++ returns 3 and, only then, sets x to 4. |
Decrement (–) | Unary operator. Subtracts one from its operand. The return value is analogous to that for the increment operator. | If x is 3, then --x sets x to 2 and returns 2, whereas x-- returns 3 and, only then, sets x to 2. |
Unary negation (-) | Unary operator. Returns the negation of its operand. If x is 3, then -x returns -3. | |
Unary plus (+) | Unary operator. Attempts to convert the operand to a number, if it is not already. +“3” returns 3.+true returns 1. | |
Exponentiation operator (** ) |
Calculates the base to the exponent power, that is, baseexponent 2 ** 3 returns 8.10 ** -1 returns 0.1. |
4.Bitwise operators
Operator | Usage | Description |
---|---|---|
Bitwise AND | a & b | Returns a one in each bit position for which the corresponding bits of both operands are ones. |
Bitwise OR | a | b |
Returns a zero in each bit position for which the corresponding bits of both operands are zeros. |
Bitwise XOR | a ^ b | Returns a zero in each bit position for which the corresponding bits are the same. |
Bitwise NOT | ~ a | Inverts the bits of its operand. |
Left shift | a << b | Shifts a in binary representation b bits to the left, shifting in zeros from the right. |
Sign-propagating right shift | a >> b | Shifts a in binary representation b bits to the right, discarding bits shifted off. |
Zero-fill right shift | a >>> b | Shifts a in binary representation b bits to the right, discarding bits shifted off, and shifting in zeros from the left. |
5.Logical operators
Operator | Usage | Description |
---|---|---|
Logical AND (&&) | expr1 && expr2 | Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false. |
Logical OR (|| ) |
expr1 || expr2 |
Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, |
Logical NOT (!) | !expr | Returns false if its single operand that can be converted to true; otherwise, returns true. |
Unary operators
delete
typeof
void
<a href="javascript:void(0)">Click here to do nothing</a>
<a href="javascript:void(document.form.submit())">Click here to submit</a>
in
instanceof
参考:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
来源:CSDN
作者:Claroja
链接:https://blog.csdn.net/claroja/article/details/104311935