Do I need to "come back" after "throw" in JavaScript?

I selected Error from my method, from which I need an early exit, as shown below:

 // No route found if(null === nextRoute) { throw new Error('BAD_ROUTE'); } 

I need to put a return; after my throw ? At the moment this works for me. If this is superfluous, I would prefer not to embed it, but I cannot be sure what different browsers can do.

+43
javascript exception error-handling
Sep 26 '14 at 19:44
source share
1 answer

You do not need to set the return after throw , the return line will never be reached, since throwing an exception immediately sends control back to the caller.

+72
Sep 26 '14 at 19:48
source share
— -



All Articles