What\'s the difference between |
and ||
in Javascript?
Furthermore, what\'s the difference between &
and &&<
&
is the bitwise AND operator
|
is the bitwise OR operator
&&
is the logical AND operator
||
is the logical OR operator
The difference is that logical operators only consider each input at face value, treating them as whole, while bitwise operators work at the bit level:
var thetruth = false;
var therest = true;
var theuniverse = thetruth && therest; //false
var theparallel = thetruth && thetruth; //true
var theindifferent = thetruth || therest; //true
var theideal = thetruth || thetruth; // false
var thematrix = 5346908590;
var mrsmith = 2354656767;
var theoracle = thematrix & mrsmith; //202445230
var theone = thematrix | mrsmith; //7499120127