2

Is there a shorthand version of writing something like this:

let parsed;

try {
  parsed = JSON.parse(somedata);
} catch (e) {}

someFunction(parsed || {});

I'm thinking more in the lines of this:

const parsed = try JSON.parse(somedata);

someFunction(parsed || {});

Obviously this specific example is super contrived, but I'm curious to know if there is something like it.

Kloar
  • 1,109
  • 2
  • 9
  • 25
  • There is no way I know of to shorten down `try`/`catch` blocks. My suggestion is to remove all new-lines and have it inline. – Alex Jun 20 '18 at 14:35
  • 3
    Possible duplicate of [Try/catch oneliner available?](https://stackoverflow.com/questions/5126560/try-catch-oneliner-available) – Ruud Helderman Jun 20 '18 at 14:36

0 Answers0