Is there anyway to implement XOR in javascript

前端 未结 18 667
孤城傲影
孤城傲影 2020-12-24 10:53

I\'m trying to implement XOR in javascript in the following way:

   // XOR validation
   if ((isEmptyString(firstStr) && !isEmptyString(secondStr)) |         


        
18条回答
  •  -上瘾入骨i
    2020-12-24 11:43

    As others have pointed out, logical XOR is the same as not-equal for booleans, so you can do this:

    
      // XOR validation
      if( isEmptyString(firstStr) != isEmptyString(secondStr) )
        {
          alert(SOME_VALIDATION_MSG);
          return;
        }
    

提交回复
热议问题