jimfog Posted July 29, 2015 Share Posted July 29, 2015 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 More sharing options...
justsomeguy Posted July 29, 2015 Share Posted July 29, 2015 It looks like the check for deletestate is redundant because it does the same thing either way. Link to comment Share on other sites More sharing options...
jimfog Posted July 29, 2015 Author Share Posted July 29, 2015 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 More sharing options...
justsomeguy Posted July 29, 2015 Share Posted July 29, 2015 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 More sharing options...
jimfog Posted July 29, 2015 Author Share Posted July 29, 2015 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 More sharing options...
ShadowMage Posted July 29, 2015 Share Posted July 29, 2015 Based on the AJAX comments, I'd say a different request would be sent, depending on deletestate. That said, the code could be restructured to be more efficient and/or make more sense. Link to comment Share on other sites More sharing options...
jimfog Posted July 29, 2015 Author Share Posted July 29, 2015 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 More sharing options...
ShadowMage Posted July 30, 2015 Share Posted July 30, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now