The throw statement in JS

The throw statement is used to throw a defined exception. The execution of the current function will be stopped (the instructions located after the throw instruction will not be executed) and control will be passed to the first catch block. If there is no catch block, the program will be terminated.
With ECMAScript 2019/ES10, we have an Optional Catch Binding: we can use try/catch without creating an unused binding and we are free to go ahead make use of catch block without a param, you can see below the example:

try {
throw new Error ('some error')
// 'errorMessage'

If you like this article share and clap 👏 👏. Thanks!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store