JS try catch Optional catch binding update in ES10/2019

JavaScript , 0 Comments

In this article, we will learn about the new feature of JS try catch Optional catch binding. We will understand it with some comparative examples. So, Let’s start…

First of all, See this to Understand Try Catch Finally JavaScript

The JS try catch got an update of Optional catch binding in ES10/2019, If you did not aware of try catch error handling statement you can read here on MDN or you can look at this simple example below:

Basic example of try-catch

try {
catch(error) {
  // expected output: ReferenceError: nonExistentFunction is not defined
  // Note - error messages will vary depending on browser

Did you noticed that in the above example catch statement with the binding having error parameter. That error parameter is using to identify which type of error happened in the try statement. But now in the update of ES10/2019, That binding and parameter are fully optional, which means you don’t really have to write that binding when using the try catch statement. This is useful if you don’t have a need for the exception object in the code that handles the exception. Like an example below:

try {
} catch { // → No binding or parameter!

Browser Support

Support data as per chrome v8 blog

Optional catch binding 66 ? 58 yes ?

That’s all the update is about. Thank you for reading. Share and follow us for the latest updates!

Leave a Reply

Your email address will not be published.