2017-02-13 72 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