there isn’t any*

I found myself wondering about this because I tend to use the most succinct syntax above, while having an uncomfortable feeling in the back of my mind like my error object might be a bit lacking.

Turns out I had nothing to worry about, my error object is definitely average, at least it is functionally equivalent to the others.

*There is a caveat here though. If you want access to the error object before it is caught – let’s say to add some property of some kind use:
Error or new Error().

You can’t do:
const myError = throw 'that didn\'t go well'
you’ll get
SyntaxError: expected expression, got keyword 'throw'

Instead:
const myError = new Error('that didn\'t go well)
myError.timestamp = new Date();

Last modified: August 13, 2020

Author