Illegal error return statement when using return

0

with the alert and what I want to do is that for example if paracentral2 arrives empty or pextremos2 arrives empty it shows me the alaer saying that it is not standard modulation, but when I put it false return so that it does not run anymore the code appears to me error of > Uncaught SyntaxError: Illegal return statement or how do I just stop the allerger already stop and do not continue executing more code.

if (check.checked & minusTP == '810') {
     if (paraAcentral2 == "" || pextremos2 == "") {
          alert("No es modulación estandar.")
          ctx.clearRect(0, 0, 1170, 500);
          ctx.strokeStyle = "#0000";
          ctx.stroke();
          return false;   
       }  
   }

The idea is that the return does not stop drawing in the canvas

  

Uncaught SyntaxError: Illegal return statement

    
asked by Eduard 09.05.2017 в 01:58
source

2 answers

0

Since you do not give the code of the whole method, I am going to limit myself to interpreting the code that you have passed: The failure gives it to you because the return is within the if , and even if you assume that you are going to enter the if the "interpreter" of the code does not know it. That is, if you do not enter the if , the code will not return anything because there is no return out, so the code should be something like this:

function nombreFuncion(){
    var booleano=true; //Pongo true porque doy por hecho que quieres que sea 
                       //el valor por defecto.
    if (check.checked & minusTP == '810') {
     if (paraAcentral2 == "" || pextremos2 == "") {
          alert("No es modulación estandar.")
          ctx.clearRect(0, 0, 1170, 500);
          ctx.strokeStyle = "#0000";
          ctx.stroke();
          booleano=false;   
       }  
   }
    return booleano;
}

With this code you ensure that if you enter the if you will return a false , but if the variables for Central2 or pextremos2 do not arrive empty, returns true .

    
answered by 09.05.2017 / 08:47
source
0

In principle you should remove the return false; , since as you will see javascript it tells you that it does not go there, now that if for some reason that I do not know (since the code you give is not enough as to determine why the error) the return false; should go there, because the only thing I can think of you to do is catch the error with try {..} cat (err) {...} .

Example:

    if (check.checked & minusTP == '810') {
     if (paraAcentral2 == "" || pextremos2 == "") {
      alert("No es modulación estandar.")
      ctx.clearRect(0, 0, 1170, 500);
      ctx.strokeStyle = "#0000";
      ctx.stroke();
      try {
       eval("return false;");
      } catch(err) {
        console.log(err);
      }
     }
    }

You must bear in mind that this answer is to give a solution based on the context you give (which is practically nothing), it is up to you to opt for it or give more information for an absolute response to the problem.

    
answered by 09.05.2017 в 03:42