I am not getting what or
operator does with inters. I have following code
-1||4 // output -1
4||-1 //output 4
Does it converts integers in bytes and performs or operation.
I am not getting what or
operator does with inters. I have following code
-1||4 // output -1
4||-1 //output 4
Does it converts integers in bytes and performs or operation.
It first checks wheter the number is truthy
or falsey
and returns the first truthy
one. All numbers are truthy except for 0
.
0 || 4; // 4
2 || 3; // 2 (picks the first one, because both true)
-3 || 0; // -3
0 || -2; // -2
Does it converts integers in bytes and performs or operation?
No. The ||
operator is logical and
, not bitwise and
.