JavaScript 中的位或赋值运算符 (|=) 是什么?


它对右操作数与左操作数执行 OR 运算,并将结果赋值给左操作数。

示例

你可以尝试运行以下代码来学习如何使用位或赋值运算符 −

<html>
   <body>
      <script>
         var a = 2; // Bit presentation 10
         var b = 3; // Bit presentation 11

         document.write("(a |= b) => ");
         document.write(a |= b);
      </script>
   </body>
</html>

更新于: 2020 年 6 月 13 日

192 次查看

开启你的 职业生涯

完成课程获得认证

开始吧
广告