Javascript logical operators and results

前端 未结 2 1334
星月不相逢
星月不相逢 2021-02-11 04:20

I know that the result of logical operations in most of the languages is either true, false or 1,0. In Javascript I tried the following:

alert(6||5)  // => re         


        
2条回答
  •  攒了一身酷
    2021-02-11 04:41

    Actually what you have derived are the pure digital results...like...

       3 in binary is 011......
       4 in binary is 100.....
    
       when u perform 3|4......
    
       it is equivalent to 011|100......i.e the OR operator which is the one of the bases of all logical operations
    
           011
           100
    
       will give 111 ie 7.............
    
       so u will get 3|4  as 7......
    
       hope u understand..
    

提交回复
热议问题