JavaScript 中所有二元运算符的列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12122293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:22:42  来源:igfitidea点击:

List of all binary operators in JavaScript

javascriptoperators

提问by fakeguybrushthreepwood

I am trying to understand what is possible with binary operators (only binary operators) in JavaScript. So far the list of binary operators I have discovered are the the following. They are primarily sourced from this list, but are any missing?

我试图了解 JavaScript 中的二元运算符(仅限二元运算符)有什么可能。到目前为止,我发现的二元运算符列表如下。它们主要来自此列表,但是否缺少任何内容?

Note, I am after specifically only binaryoperators which, according to the source listed above, is defined as binary operators you use with two objects (is this accurate?). I have also added the additions from @zessx.

请注意,我只关注二元运算符,根据上面列出的来源,它被定义为您与两个对象一起使用的二元运算符(这是否准确?)。我还添加了来自@zessx 的补充。

+   //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

回答by Bergi

You will find a complete list in the specification, in the expression chapter. Because the most "normal" operators are binary (see the definition at Wikipedia), they are not explicitly listed as such (like the unary and ternary operators). They are:

您将在规范中的表达式章节中找到完整列表。由于最“正常”的运算符是二元运算符(请参阅Wikipedia 上定义),因此它们并未明确列出(如一元运算符和三元运算符)。他们是:

  • Multiplicative Operators
    • The *Operator
    • The /Operator
    • The %Operator
  • Additive Operators
    • The Addition operator (+)
    • The Subtraction Operator (-)
  • Bitwise Shift Operators
    • The Left Shift Operator (<<)
    • The Signed Right Shift Operator (>>)
    • The Unsigned Right Shift Operator (>>>)
  • Relational Operators
    • The Less-than Operator (<)
    • The Greater-than Operator (>)
    • The Less-than-or-equal Operator (<=)
    • The Greater-than-or-equal Operator (>=)
    • The instanceofoperator
    • The inoperator
  • Equality Operators
    • The Equals Operator (==)
    • The Does-not-equals Operator (!=)
    • The Strict Equals Operator (===)
    • The Strict Does-not-equal Operator (!==)
  • Binary Bitwise Operators (&, ^, |)
  • Binary Logical Operators (&&, ||)
  • 乘法运算符
    • *运营商
    • /运营商
    • %运营商
  • 加法运算符
    • 加法运算符 ( +)
    • 减法运算符 ( -)
  • 按位移位运算符
    • 左移运算符 ( <<)
    • 有符号右移运算符 ( >>)
    • 无符号右移运算符 ( >>>)
  • 关系运算符
    • 小于运算符 ( <)
    • 大于号运算符 ( >)
    • 小于或等于运算符 ( <=)
    • 大于或等于运算符 ( >=)
    • instanceof运营商
    • in运营商
  • 等号运算符
    • 等号运算符 ( ==)
    • 不等于运算符 ( !=)
    • 严格等于运算符 ( ===)
    • 严格不等于运算符 ( !==)
  • 二元按位运算符 ( &, ^, |)
  • 二元逻辑运算符 ( &&, ||)

Technically speaking, also the assignment and comma operators are binary.

从技术上讲,赋值和逗号运算符也是二进制的。

回答by blasteralfred Ψ

There are the following arithmetic operators supported by the JavaScript language.

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

Assume variable A holds 10 and variable B holds 20 then:

假设变量 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

在此处输入图片说明

Hereis the original page link.

是原始页面链接。

回答by zessx

+   //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