The throw statement in JS

ahmedSoua
Aug 23, 2021

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')
}catch{
console.log('errorMessage')
}
// 'errorMessage'

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

--

--