Skip to content

JavaScript equivalent of PHP’s die

Is there something like “die” in JavaScript? I’ve tried with “break”, but doesn’t work 🙂


You can only break a block scope if you label it. For example:

myBlock: {
  var a = 0;
  break myBlock;
  a = 1; // this is never run
a === 0;

You cannot break a block scope from within a function in the scope. This means you can’t do stuff like:

foo: { // this doesn't work
  (function() {
    break foo;

You can do something similar though with functions:

function myFunction() {myFunction:{
  // you can now use break myFunction; instead of return;