What's the difference between ( | ) and ( || )?

前端 未结 7 1221
故里飘歌
故里飘歌 2020-12-01 14:08

What\'s the difference between | and || in Javascript?

Furthermore, what\'s the difference between & and &&<

相关标签:
7条回答
  • 2020-12-01 15:09
    • & 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
    
    0 讨论(0)
提交回复
热议问题