2012-08-25 16 views
8

我想了解JavaScript中的二元运算符(只有二元运算符)可能会发生什么。到目前为止,我发现的二元运算符列表如下。他们主要来源于this list,但是缺失?JavaScript中所有二元运算符的列表

注意,我特别是后二进制运算符,根据上面列出的来源,被定义为二元运算符您使用两个对象(这是否准确?)。我还添加了@samsamX的新增内容。

+ //Add 
- //Subtract 
/ //Divided by 
* //Multiple 
% //Modulus 
< //Less than 
> //Greater than 
& //AND 
| //OR 
^ //XOR 
~ //Invert each bits 
<< //Move all bits onto the left 
>> //Move all bits onto the right 
>>> //Move all bits onto the right and fill left end with 0 
+0

还有一些二进制运算符,比如'|' (或)和'&'为和。 –

+1

google上的第一个结果:http://web.eecs.umich.edu/~bartlett/jsops.html – devundef

+0

这似乎是所有运营商的视频指南:http://bateru.com/news/2011/03/ javascript-binary-operations-the-easy-way/ – devundef

回答

11

在表达章节中,您可以在specification中找到完整列表。由于大多数“正常”运算符是二进制的(请参见definition at Wikipedia),因此它们没有明确列出(像一元运算符和三元运算符)。它们是:

  • 乘法运算
    • *操作
    • /操作
    • %操作
  • 加法运算符
    • 加法运算符(+
    • 减法运算符(-
  • 按位移位运算符
    • 左移操作符(<<
    • 的签名向右移位运算符(>>
    • 无符号右移运算符(>>>
  • 关系运算符
    • 的小于运算符(<
    • 的大于运算符(>
    • 的低于或相等的运算符(<=
    • 的大 - 等于或等于运算符(>=
    • instanceof运算符
    • in运营商
  • 相等运算
    • 等于运算符(==
    • 的不 - 不等于运算符(!=
    • 严格等于运算符(===
    • 严格不 - 不等于运营商(!==
  • 个二进制位运算符(&^|
  • 二元逻辑运算符(&&||

从技术上来说,也是分配和逗号操作符都是二元。

1
+ //Add 
- //Subtract 
/ //Divided By 
* //Multiple 
% //Modulus 
< //Less than 
> //Greater than 
! //Not 
& //And 
| //Or 
^ //Xor 
~ //Invert each bits 
<< //Move all bits onto the left 
>> //Move all bits onto the right 
>>> //Move all bits onto the right and fill left end with 0 
+2

'!'和'〜'不是二元运算符 – Bergi

9

JavaScript语言支持以下算术运算符。

假设变量A持有10和变量B持有20然后:

Enter image description here

Enter image description here

Enter image description here

Enter image description here

Enter image description here

Enter image description here

Here是原来的网页链接。

+0

条件表达式(也称为* *三元运算符)不是*二元运算符。 – Bergi

+0

@Bergi在这篇文章后,这个问题被修改了。最初它是在谈论所有的运营商。 –

+0

好的,但是你忘了所有那些一元运算符,比如'!'或'new' ... – Bergi

相关问题