Why is there no logical xor in JavaScript?

前端 未结 19 2106
忘了有多久
忘了有多久 2020-11-29 17:17

Why is there no logical xor in JavaScript?

19条回答
  •  抹茶落季
    2020-11-29 17:24

    In above xor function it will result SIMILAR result as logical xor does not exactly logical xor, means it will result "false for equal values" and "true for different values" with data type matching in consideration.

    This xor function will work as actual xor or logical operator, means it will result true or false according to the passing values are truthy or falsy. Use according to your needs

    function xor(x,y){return true==(!!x!==!!y);}
    
    function xnor(x,y){return !xor(x,y);}
    

提交回复
热议问题