If you are a javascript developer then you definitely know about try-catch block which is used to deal with errors. But now you can use new Safe Assignment operator proposal (?=)
try-catch blocks lead to nested code making it harder to read and maintain.
?= operator reduces nesting and it gives result of function into tuple.
If an error occurs, it returns [error,null]otherwise it returns [null, result].
async function fetchData() { const [error, response] ?= await fetch("https://api.example.com/data"); if (error) return handleError(error); return response; }
The above is the detailed content of No need of Try-Catch!! Javascript introduced new safe assignment operator✌. For more information, please follow other related articles on the PHP Chinese website!