Optional Catch Binding in JavaScript ES10
Overview of Option Catch Binding
The optional catch binding is a new feature in JavaScript that was added in the ES10/2019, this feature is useful in some cases when you don't need the binding parameter in the catch clause.
try {
// do something
} catch (error) {
// we have error parameter to handle it
}
Without optional catch binding
try {
// do something
} catch {
// no binding or parameter to handle it
}
With optional catch binding ES10/2019
As we see our examples above, in the first example you have an error parameter which was not optional before ES2019/10, wherein the second example as you can see the error parameter is not there, because it is optional in the ES2019/10. In the past it was always needed to have the parameter whatever you use it or not, this feature is very useful if you never use the variable error as you don't need for the exception object in the code that handles the exception.
Note: If you are new to JavaScript you can go on the following link to learn more about the try-catch-finally
Browser Support
Chrome | Firefox | Safari | IE/Edge | Node |
---|---|---|---|---|
66+ | 58+ | ? | ? | 8+ |
I hope you understand how the optional catch binding works in JavaScript if you find this article useful please share it.
Tweet