Is there something like "die" in JavaScript? I've tried with "break", but doesn't work :)
Is there something like "die" in JavaScript? I've tried with "break", but doesn't work :)
There is no function exit equivalent to php die() in JS, if you are not using any function then you can simply use return;
return;
Global die() function for development purposes:
var die = function(msg) {
throw new Error(msg);
}
Use die():
die('Error message here');
This should kind of work like die();
function die(msg = ''){
if(msg){
document.getElementsByTagName('html')[0].innerHTML = msg;
}else{
document.open();
document.write(msg);
document.close();
}
throw msg;
}