FrontendDeveloper.in

ECMAScript question detail

Optional catch binding

Prior to ES9, if you don't need error variable and omit the same variable then catch() clause won't be invoked. Also, the linters complain about unused variables. Inorder to avoid this problem, the optional catch binding feature is introduced to make the binding parameter optional in the catch clause. If you want to completely ignore the error or you already know the error but you just want to react to that the this feature is going to be useful.

Let's see the below syntax difference between the versions,

// With binding parameter(<ES9)
try {
···
} catch (error) {
···
}
// Without binding parameter(ES9)
try {
···
} catch {
···
}

For example, the feature detection on a browser is one of the most common case

let isTheFeatureImplemented = false;
try {
if(isFeatureSupported()) {
isTheFeatureImplemented = true;
}
} catch (unused) {}
Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399