«   Previous tip Next tip   »

JavaScript: A simpler JavaScript try/catch worth knowing about

Last updated: 7th March 2023

Introduction

Make sure you have a valid use case before doing this! But optional catch binding is a little feature worth knowing about:

Before, with the catch binding:

try {
    await fetch();
} catch (err) {
    console.log(`No that didn't work`);
}

After, without the catch binding:

try {
    await fetch();
} catch {
    console.log(`No that didn't work`);
}

Supported in all modern web browsers. Check here for browser support.

«   Previous tip Next tip   »

Sign up to receive a developer tip, in the form of a gif, in your inbox each week