<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx" -->

---
title: Bye Bye, Try-Catch Blocks: Meet JavaScript&#x27;s Safe...
description: The proposed Safe Assignment Operator (`?=`) in JavaScript aims to simplify error handling by reducing the need for traditional try-catch blocks. This operator...
canonical: https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Bye Bye, Try-Catch Blocks: Meet JavaScript&#x27;s Safe Assignment Operator Proposal😉 | daily.dev
og:description: The proposed Safe Assignment Operator (`?=`) in JavaScript aims to simplify error handling by reducing the need for traditional try-catch blocks. This operator...
og:url: https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx
og:image: https://api.daily.dev/og/posts/FkYjE8MxX.png
og:image:alt: Bye Bye, Try-Catch Blocks: Meet JavaScript&#x27;s Safe Assignment Operator Proposal😉
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Bye Bye, Try-Catch Blocks: Meet JavaScript's Safe Assignment Operator Proposal😉

**[Community Picks](https://daily.dev/sources/community)** · 4 min read · 7311 upvotes · 214 comments

## Summary

The proposed Safe Assignment Operator (`?=`) in JavaScript aims to simplify error handling by reducing the need for traditional try-catch blocks. This operator transforms function results into a tuple, improving code readability and consistency across APIs. It also automatically handles errors, enhancing security. Inspired by constructs in languages like Go, Rust, and Swift, it supports integration with Promises and async functions and offers customizable error handling via `Symbol.result`.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/dharamgfx/bye-bye-try-catch-blocks-meet-javascripts-safe-assignment-operator-proposal-1j7>

## Community discussion

Top comments from developers on daily.dev.

**@0xtonyth** · 144 upvotes

> FYI: This is just a DRAFT PROPOSAL
>
> Proposal: https://github.com/arthurfiorette/proposal-safe-assignment-operator

**@raflie** · 118 upvotes

> 😱 is golang coming to javascript?
>
> (it is one of my favourite features in golang btw)

**@raflie** · 60 upvotes

> > Consistency Across APIs
>
> while i agree that this would reduce nested try-catch in our code, this would probably just bloat the javascript syntaxes. because we could already do that with a wrapper function without having to add new syntax. we can just add an extension to the function prototype
>
> ```js
>
> Function.prototype.toSafe = function() {
>   try {
>     const result = this();
>     return [null, result];
>   } catch (error) {
>     return [error, null]
>   }
> }
>
> const hello  = () => 'world';
> const notSafe = () => { throw new Error('world') };
>
> hello.toSafe()
> notSafe.toSafe()
>
> Promise.prototype.toSafe...

**@bishal56** · 14 upvotes

> Just when I moved to Golang haha.

**@v4sj4n** · 8 upvotes

> golangification

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Bye Bye, Try-Catch Blocks: Meet JavaScript's Safe Assignment Operator Proposal😉","url":"https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx"},"datePublished":"2024-08-24T14:47:31.508Z","dateModified":"2024-11-07T13:47:25.446Z","description":"The proposed Safe Assignment Operator (`?=`) in JavaScript aims to simplify error handling by reducing the need for traditional try-catch blocks. This operator...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e0d5b7daf82c69aa2efe7a19c7d2bbc3?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e0d5b7daf82c69aa2efe7a19c7d2bbc3?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"Community Picks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Community Picks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1655817725/logos/community","url":"https://daily.dev/sources/community"},"commentCount":214,"discussionUrl":"https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":7311},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":214}],"keywords":"webdev,javascript","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Community Picks","item":"https://daily.dev/sources/community"},{"@type":"ListItem","position":3,"name":"Bye Bye, Try-Catch Blocks: Meet JavaScript's Safe Assignment Operator Proposal😉"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/bye-bye-try-catch-blocks-meet-javascript-s-safe-assignment-operator-proposal--fkyje8mxx","comment":[{"@type":"Comment","text":"FYI: This is just a DRAFT PROPOSAL\nProposal: https://github.com/arthurfiorette/proposal-safe-assignment-operator","datePublished":"2024-08-25T13:35:11.677Z","url":"https://daily.dev/posts/FkYjE8MxX#c-E8hRBl3iC","author":{"@type":"Person","name":"Tony Thomás","url":"https://daily.dev/0xtonyth","image":"https://media.daily.dev/image/upload/s--FCVJBY9j--/f_auto/v1721925020/avatars/avatar_9aU1RU9hds0pYPLXnaNcZ"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":144}},{"@type":"Comment","text":"😱 is golang coming to javascript?\n(it is one of my favourite features in golang btw)","datePublished":"2024-08-25T17:42:53.287Z","url":"https://daily.dev/posts/FkYjE8MxX#c-49UePcEbC","author":{"@type":"Person","name":"Raflie","url":"https://daily.dev/raflie","image":"https://lh3.googleusercontent.com/a/AAcHTtd3_211Bnaq0FEbZnJW90QaXtt6U5DU_2qrSQ0Ulucm4g=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":118}},{"@type":"Comment","text":"Consistency Across APIs\n\nwhile i agree that this would reduce nested try-catch in our code, this would probably just bloat the javascript syntaxes. because we could already do that with a wrapper function without having to add new syntax. we can just add an extension to the function prototype\n\nFunction.prototype.toSafe = function() {\n  try {\n    const result = this();\n    return [null, result];\n  } catch (error) {\n    return [error, null]\n  }\n}\n\nconst hello  = () =&gt; &#x27;world&#x27;;\nconst notSafe = () =&gt; { throw new Error(&#x27;world&#x27;) };\n\nhello.toSafe()\nnotSafe.toSafe()\n\nPromise.prototype.toSafe = function() {\n  return this\n    .then((result) =&gt; [null, result])\n    .catch((error) =&gt; [error, null])\n}\n\nawait Promise.resolve(&#x27;hello&#x27;).toSafe()\nawait Promise.reject(new Error(&#x27;world&#x27;)).toSafe()\n\nconst [error, data] = await fetch(&#x27;...&#x27;).toSafe()\n\n\nImproved Security\n\nwhat even? this has never been an issue in the javascript programming, on what situation where the current javascript try-catch method has lead to ‘unnoticed bugs and potential security risks’?\nand how does const [error, ]?= ... promote bugs handling if it can be ignored const [, data] ?= ... like how we do in the try-catch try {} catch (ignored) { // }","datePublished":"2024-08-25T18:03:34.985Z","dateModified":"2024-08-29T05:33:20.832Z","url":"https://daily.dev/posts/FkYjE8MxX#c-ozE5ylTZ2","author":{"@type":"Person","name":"Raflie","url":"https://daily.dev/raflie","image":"https://lh3.googleusercontent.com/a/AAcHTtd3_211Bnaq0FEbZnJW90QaXtt6U5DU_2qrSQ0Ulucm4g=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":60}},{"@type":"Comment","text":"Just when I moved to Golang haha.","datePublished":"2024-08-25T17:50:51.751Z","url":"https://daily.dev/posts/FkYjE8MxX#c-6gd6aSCrW","author":{"@type":"Person","name":"Bishal","url":"https://daily.dev/bishal56","image":"https://lh3.googleusercontent.com/a/ACg8ocJceEYQHglT3ARZb41oQpmUgQHKZ_yi2QpyGfSYMj-Lcg=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14}},{"@type":"Comment","text":"golangification","datePublished":"2024-08-25T18:14:49.906Z","url":"https://daily.dev/posts/FkYjE8MxX#c-WTWUJvQyz","author":{"@type":"Person","name":"Vasjan Çupri","url":"https://daily.dev/v4sj4n","image":"https://media.daily.dev/image/upload/s--4ggztBd2--/f_auto/v1784188921/avatars/avatar_M6leN0gUvkzZoHtq9xHSo?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":8}}]}
```

