“;或“;具有整数的运算符

What is the use of "or" operator with integers

本文关键字:运算符 整数      更新时间:2023-09-26

我没有得到or运算符对inters的作用。我有以下代码

-1||4  // output -1
4||-1  //output  4  

它是否转换以字节为单位的整数并执行或运算。

它首先检查数字是truthy还是falsey,并返回第一个truthy。除了0之外,所有的数字都是真的。

0  || 4;  //  4
2  || 3;  //  2 (picks the first one, because both true)
-3 || 0;  // -3
0  || -2; // -2

它是否转换以字节为单位的整数并执行或运算?

没有。||运算符是logical and,而不是bitwise and