Skip to content

re: CATCH block after IF statement block instead of TRY? VIEW POST

re: No sample Sean. Just in my head which is full of coding nonsense as well as other stuff. 😊

Sean, what she's saying is that the code block in the question is basically shorthand for the following:

if (!e.stack) {
    try {
         throw e;
    } catch(e) {
         if (!e.stack) {
             return 0;

...and that this is the case because in JavaScript (and other C-like languages), if you have only one statement that you would like to execute in an IF-statement, you can drop the brackets:

if(myBool) myNum += 2;

// Is the same as
if(myBool) {
    myNum += 2;

Thanks Sam. That’s perfect and a little too much for me to type on my phone.

code of conduct - report abuse