I’ve been going through Medium to get some updates about programming. A couple of articles confused me that were related to "Safe Assignment Operator":
async function getData() {
const [networkError, res] ?= await fetch('https://api.backend.com/resource/1')
if(networkError) console.error(networkError)
const [parseError, data] ?= await res.json()
if(parseError) console.error(parseError)
return data
}
I tried finding the official documentation on MDN, but nothing found. I also tried on console but no luck.
Is this a myth or isn’t the MDN site updated?
Here is the article that build up the confusion. Medium Article
1
Answers
There is a proposal for a safe assignment operator (
?=
). The aim is to simplify error handling without needing try/catch but using:as opposed to:
However, this is still a very early proposal that does not even show up on the proposal track for ECMAScript. This is typically a six stage process with stage zero being just marked as there but not yet considered. The proposal is not at stage zero yet.
Moreover, the earliness of the proposal is evident by looking at its README which currently says on top:
So, it can change further before even entering the proposal track from TC39.