2017-02-13 42 views
-2

我只想检查else条件。有没有一种方法可以简化下面的代码?这个逻辑语句的反义词是什么

 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"); 
     } 
+0

啊,这是正确的,但我更喜欢第一种方法 –

+0

但我并不需要检查的第一个if语句。只需要执行else语句 – noob

+0

那么伤心,人们只是低估了我的问题。这并不是说我没有试图解决它 – noob

回答

0

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

这将是这样的:

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

谢谢,德文! – noob