javascript operators(操作符)

1.Assignment operators(分配操作)

NameShorthand operatorMeaning
Assignmentx = yx = y
Addition assignmentx += yx = x + y
Subtraction assignmentx -= yx = x - y
Multiplication assignmentx *= yx = x * y
Division assignmentx /= yx = x / y
Remainder assignmentx %= yx = x % y
Exponentiation assignmentx **= yx = x ** y
Left shift assignmentx <<= yx = x << y
Right shift assignmentx >>= yx = x >> y
Unsigned right shift assignmentx >>>= yx = x >>> y
Bitwise AND assignmentx &= yx = x & y
Bitwise XOR assignmentx ^= yx = x ^ y
Bitwise OR assignmentx |= yx = x | y

2.Comparison operators(比较运算符)

OperatorDescriptionExamples 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

OperatorDescriptionExample
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

OperatorUsageDescription
Bitwise ANDa & bReturns a one in each bit position for which the corresponding bits of both operands are ones.
Bitwise ORa | bReturns a zero in each bit position for which the corresponding bits of both operands are zeros.
Bitwise XORa ^ bReturns a zero in each bit position for which the corresponding bits are the same.
Bitwise NOT~ aInverts the bits of its operand.
Left shifta << bShifts a in binary representation b bits to the left, shifting in zeros from the right.
Sign-propagating right shifta >> bShifts a in binary representation b bits to the right, discarding bits shifted off.
Zero-fill right shifta >>> bShifts a in binary representation b bits to the right, discarding bits shifted off, and shifting in zeros from the left.

5.Logical operators

OperatorUsageDescription
Logical AND (&&)expr1 && expr2Returns 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 || expr2Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values,
Logical NOT (!)!exprReturns 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值