How to terminate the JavaScript script running?

How can exit the JavaScript script like PHP’s exit or die? Sometimes I need do this.

“exit” functions usually exit the program or script along with an error message as parameter. For example, die(…) in php

die("some string left")

The equivalent in JS is to signal an error with the throw keyword like this:

throw new Error();

You can easily test this:

var m = 100;
throw '';
var x = 100;

x
>>>undefined
m
>>>100

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *