JavaScript equivalent of PHP’s die()

Sometimes we want to finish the execution of the script below.

In PHP, we can do this with die().

JS doesn’t have its 1:1 equivalent, but we can achieve the similar results with

1. Error

throw new Error("error message");

2. Empty return

If it’s inside the function, just use return: