PHP's exit; in Javascript?
You could try:
throw "stop execution";
Using return you will skip the current function, that's why throwing is more similar to PHP exit();
A javascript function is terminated by calling return
. Usually you will be in the context of a function or something. Also event handlers (like for onclick
on an element) will behave like a function and accept return.
I would finish a function early with a return statement:
return;