No need of Try-Catch!! Javascript introduced new safe assignment operator✌

WBOY
Release: 2024-08-25 15:00:36
Original
359 people have browsed it

No need of Try-Catch!! Javascript introduced new safe assignment operator✌

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].

Example-

async function fetchData() { const [error, response] ?= await fetch("https://api.example.com/data"); if (error) return handleError(error); return response; }
Copy after login

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!