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

を好むだろうが、私は文の場合は、最初に確認する必要がありません。 else文を実行する必要があります – noob

+0

悲しい、人々はちょうど私の質問をd​​ownvote。それは私がそれを解決しようとしていないわけではありません – noob

答えて

0

あなたは&& Sを!を配布するためにDe Morgan's Lawを使用することができます。このようになります。

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

ありがとう、Devin! – noob

関連する問題