什么是“|” (单管)用JavaScript做什么? [英] What does the "|" (single pipe) do in JavaScript?
本文介绍了什么是“|” (单管)用JavaScript做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
console.log(0.5 | 0); // 0
console.log(-1 | 0); // -1
console.log(1 | 0); // 1
为什么 0.5 | 0
返回零,但是任何整数(包括负数)都返回输入整数?单管(|)做什么?
Why does 0.5 | 0
return zero, but any integer (including negative) returns the input integer? What does the single pipe ("|") do?
推荐答案
这是一个按位或。
由于按位操作只对整数有意义, 0.5
被截断。
0 | x
是 x
,对于任何 x
。
这篇关于什么是“|” (单管)用JavaScript做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文