什么是|接线员呢? [英] What does the | operator do?

查看:38
本文介绍了什么是|接线员呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
JavaScript中的(|)和(||)有什么区别?

我在这里的几个示例中已经看到了这一点,但我从未完全理解它应该做什么.有人可以给我一个简单的例子吗?

I've seen this in a couple examples here but I never fully understood what it's supposed to do. Can anyone give me a simple example please?

推荐答案

在Javascript中, | 运算符是按位运算符(与 ||| 运算符相反是逻辑运算符.

In Javascript, the | operator is a bitwise operators (in contrast to the || operator which is a logical operator).

它将每个操作数转换为32位数字,并按位执行或在它们之间执行.

It convert each operand to a 32-bit number, and performs a bitwise or between them.

表达式及其结果的示例:

Example of expressions and their results:

1 | 1 === 1
1 | 2 === 3
1.99 | 2.99 === 3

参考: http://developer.mozilla.org/en/JavaScript/参考/运算符/bitwise_operators

这篇关于什么是|接线员呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆