"break" javascript execution
execution, javascript
Solution
Wrap it in a function which immediately executes.
(function() {
if (already_done) { return; }
doSomeStuff();
})();
FYI: `return` is useless without being in a function context.
Also, this isn't a closure since it doesn't return an inner function which uses variables defined in an outer function.
Problem
I was wondering if there was a way to break javascript execution, something like this ``` <script> if(already_done) { return; //prevent execution (this yields an error) } doSomeStuff(); </script> ``` I know that this is possible like this: ``` <script> if(already_done) { // do nothing } else { doSomeStuff(); } </script> ``` But it's not the solution I'm looking for. Hopefully this makes sense.