3 ms·
I often find myself using an immediately invoked function expression to handle the try catch const assignment issue, for example: const result = (() => {
by throwitaway1123 2y ago
I often find myself using an immediately invoked function expression to handle the try catch const assignment issue, for example:
const result = (() => {
try {
return new URL(someString)
} catch {
return null
}
})()
It's not pretty though, and I think the do expressions proposal would rid my codebases of this pattern: https://github.com/tc39/proposal-do-expressions https://github.com/tc39/proposal-do-expressions
- IggleSniggle 2y agoThanks for this, I think your syntax is an improvement over the solutions I've tried