Question

Pretty simple question, but much to my surprise I could not find an answer on the internets.

In PHP we have exit; which will simply stops executing any further code when it reaches that line, assuming there are no errors.

Does jQuery (JAVASCRIPT for all yous) have a similar built in function? This is to be used for debugging, not for production.

Thanks!

Was it helpful?

Solution

window.stop() (vanilla JavaScript, not jQuery) would simulate the user clicking the Stop button on the browser, preventing the browser from downloading and rendering the current page.

OTHER TIPS

First, a pet peeve: there's no such language as jQuery. That's just a library framework on top of JavaScript. The question is presumably whether JavaScript has an exit function.

If you want to stop script execution, and you're in a debug environment, you have a few options, none of which are exit:

  • You can pop up an alert. This will stop execution, but doesn't let you do much.
  • You can use the debugger; statement. This may be what you want - just put it in a line, and if your console is open, it will bring up the debugger at that point.

The last alternative will work, but isn't pretty. Simply throw an exception (or cause one of your own, e.g. myNonExistantVariable.thereIsNoProperty.soExceptionWillHappen = 0;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top