这个逻辑陈述的反面是什么

时间:2017-02-13 23:27:14

标签: if-statement logical-operators simplify

我想检查其他条件。有没有办法可以简化下面的代码?

      if (_endCurrentGoal && _startCurrentGoal && _startCurrentGoal === _startEffectiveDate && _endCurrentGoal === _endEffectiveDate) { //no statement );
       } 
       else {
          console.log("check for this code only");
       }

以下代码是否正确?有没有办法简化它?

       if(!(_endCurrentGoal && _startCurrentGoal && _startCurrentGoal === _startEffectiveDate && _endCurrentGoal === _endEffectiveDate) {
          console.log("check for this code only");
       }

1 个答案:

答案 0 :(得分:0)

您可以使用De Morgan's Law通过!分发&&

这将是这样的:

   if(!_endCurrentGoal || !_startCurrentGoal || _startCurrentGoal !== _startEffectiveDate || _endCurrentGoal !== _endEffectiveDate) {
      console.log("check for this code only");
   }