Jump to content

help on using return false


jimfog

Recommended Posts

I have a javascript function with a conditonal in which I use return false...but I really do not know if the return is of any use in such a case....see the code to understand what I mean;

$('.deactivate').click(function(e){//account deletion                 if(deletestate==0)        {        if(trimmeddelpass!=="")                    {                                //ajax request here                    }                    else                    {                    $('#delerror').html('message');                    return false;                    }        }        if(deletestate==1)//to confirm deletion        {           if(trimmeddelpass!=="")        {           {                 //ajax request here           }         }           else               {                    $('#delerror').html('message');                    return false;               }          }                   });

there are two if/else statements above...in the else bracket there is "return false"...do you think it is redundant?

Link to comment
Share on other sites

It looks like the check for deletestate is redundant because it does the same thing either way.

I do not understand... what does the same thing either way?

Link to comment
Share on other sites

This is what I see:

if (deletestate == 0) {  // do something}if (deletestate == 1) {  // do the exact same thing}
So, why check the value of deletestate? Or, if it can be more than those 2 values, why not use an or?
Link to comment
Share on other sites

well I need to do some testing before answering...I cannot remember why the code is the way it is.

Link to comment
Share on other sites

That said, the code could be restructured to be more efficient and/or make more sense.

Can you give an example....

Link to comment
Share on other sites

 

if (trimmeddelpass!=="") {  if (deletestate==0) {    //Ajax request here  } else if (deletestate==1) {    //Different Ajax request here  }} else {  $('#delerror').html('message');  return false;}

Should accomplish the same thing, but you only need to do the trimmeddelpass check once and eliminate a few lines of redundant code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...