---
title: "Comment by Zsolt Gömöri on \"Error Handling in JavaScript  (Golang Style)\" | Hashnode"
description: "Nice, I dig it! Thanks Bibek Kakati ! I’d like to chime in with a minor yet potential improvement. const getData = async () =&gt; { try { const result = await m"
url: "https://hashnode.com/posts/error-handling-in-javascript-like-golang/60ccec45554b0d31c6053c47/comment/60dd99040970dd75de76f994"
---

[Discussion](https://hashnode.com/posts/error-handling-in-javascript-like-golang/60ccec45554b0d31c6053c47)

Comment [Error Handling in JavaScript (Golang Style)](https://hashnode.com/posts/error-handling-in-javascript-like-golang/60ccec45554b0d31c6053c47)

[Zsolt Gömöri](https://hashnode.com/@zsgomori)

[Jul 1, 2021](https://hashnode.com/posts/error-handling-in-javascript-like-golang/60ccec45554b0d31c6053c47/comment/60dd99040970dd75de76f994)

Nice, I dig it! Thanks [Bibek Kakati](https://hashnode.com/@bibekkakati)!

I’d like to chime in with a minor yet potential improvement.

```
const getData = async () => {
  try {
    const result = await methodCall();
    return { result };
  } catch(error) {
    return { error };
  }
}

const { result, error } = getData();

if (error) {
  // …
}
```

IMO returning an object (and destructuring both `result` and `error`) is way more readable & explicit.

[Bibek Kakati](https://hashnode.com/@bibekkakati)

[Jul 1, 2021](https://hashnode.com/posts/error-handling-in-javascript-like-golang/60ccec45554b0d31c6053c47/comment/60dd99040970dd75de76f994#reply-60dd9bc50970dd75de76fa1e)

Yeah. We can implement like this too.
