Replacing nested if statements

前端 未结 11 1929
春和景丽
春和景丽 2020-12-23 20:44

This is related to a chapter from beautiful code. And in that chapter I read about the nested ifs.

The author was talking about deeply nested if

11条回答
  •  情深已故
    2020-12-23 21:39

    You can just break once a part of the validation failed for example.

    function validate(){
      if(b=="" || b==null){
          alert("Please enter your city");
          return false;
      }
    
      if(a=="" || a==null){
          alert("Please enter your address");
          return false;
      }
      return true;
    }
    

提交回复
热议问题