1

I am new to JavaScript. Just like in Java, we have a method System.exit(), which stops current executing thread. I want to achive something similar in JavaScript. I have a flow of control, where I want to stop the execution if a particular condition is met.

I tried using exit()/ exit(0)/ exit(1) but it didn't help.

Whats the right way of doing it in JavaScript?

Don kedia
  • 11
  • 1
  • 3
  • The linked question is 100% correct. I just want to add that if you did manage to stop the current executing thread, your browser tab would die. The whole browser tab is relying on that same thread to react to user input, repaint changes, and do everything else that needs to be done to show a webpage. – Amadan Jul 10 '15 at 09:20
  • no.. that didn't help me, I don't want to throw an exception. I just want to stop there, everything else is fine. – Don kedia Jul 10 '15 at 09:27
  • How to remove this duplicate tag? – Don kedia Jul 10 '15 at 09:27
  • 1
    `window.close()` is the only thing that comes close. No, you don't want to stop javascript execution. What is your actual use case? Show some code, please. – Bergi Jul 10 '15 at 10:08
  • throw new Error(''Error message here"); or return; – Scott Jones Sep 19 '18 at 03:49

0 Answers0