2017-02-13 9 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를 사용할 수 있습니다.

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

고마워, 데빈! – noob