I need to stop my script. I don't want to write more code like if(...) return false because I will use it many times.
My English is poor. It's my first question on this site. :)
I need to stop my script. I don't want to write more code like if(...) return false because I will use it many times.
My English is poor. It's my first question on this site. :)
you can simply write return false; to do so.
return false;. (This is an example, how people answers / upvotes answers without reading the question properly. )In order to exit ALL scopes of your script, you could throw an exception and catch it at the outer scope of your script ;) This imposes, that you adapt your exception handling.
Please note: It is better to write your program in such way, that the following is NOT necessary!
function ExitException() {}
try { //Do your script-stuff here
Foo();
//and do this at any place where you wish to exit:
throw new ExitException;
}
catch (e) {
if (e instanceof ExitException) //This is an Exit. All fine.
console.log("Exit");
else //Pass Exception to the Browser
throw e;
}