I was doing some refactoring and wanted to break into the debugger and return before getting to a piece of code that made permanent changes so I put in one of my functions
return debugger;
And I got an unexpected token error (in chrome).
debugger;
return;
works just fine. Is there something in the ECMAScript spec that actually specifies this as correct behavior? Is this a browser bug? Is there any particular logic to this failing at all?
returnis optionally followed by an Expression, which when evaluated becomes the result to return.debuggeris not an expression, it’s a Statement. Soreturn debugger;fails for the same reasonreturn for (i = 0; i < 10; ++i);,return if (a > b);, etc. fail — because you can’t use statements as expressions.