| 是位运算
参加运算的两个数据按照二进制位进行“与”运算,如果两个相应的二进制位都为1,那该位的结果值就是1,否则为0,即0&0=0,0&1=0,1&1=1,1&0=0。
比如:3&5并不等于8,应该按位与 00000011&00000001=00000001。
例子:
//(取整数+换算)
console.log(2.2323 | 0) ==> 2
console.log(2.2323 | 1) ==> 3
console.log(2.2323 | 2) ==> 4
console.log(2.2323 | 3) ==> 5
//----------我以为很简单的换算方式,没想到噩梦-------------------
console.log(2 | 2) ==> 2
console.log(2 | 3) ==> 3
console.log(2 | 4) ==> 6
console.log(2 | 5) ==> 7
console.log(2 | 6) ==> 6
console.log(2 | 7) ==> 7
console.log(2 | 8) ==> 10
console.log(2 | 9) ==> 11
console.log(2 | 10) ==> 10
console.log(2 | 11) ==> 11
console.log(2 | 12) ==> 14
console.log(2 | 13) ==> 15
console.log(2 | 14) ==> 14
我疯了 这是怎么换算的啊!!!
|| 还是常用的或(如果左端为true,右端不会进行运算)
let a = '2222'
console.log(a || 14) ==> 2222
let b = '2222'
console.log(b || 6666) ==> 2222
let c = ''
console.log(c || 8888) ==> 88888