Reputation: 491
This couldn't be necessary but I'm curious.
When I used throw
statement I used to use with return like this.
return throw new Error('...')
I know there's no need the return
but it's working well so I've used this clearly.
Is there a difference between throw
and return throw
statements?
Upvotes: 3
Views: 1339
Reputation: 944430
The throw
keyword is not allowed after a return
keyword.
return throw new Error("...");
throws an exception, but not the Error object you are trying to create, it throws SyntaxError: Unexpected token throw instead.
Upvotes: 4