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; }
Atas ialah kandungan terperinci Tak perlu Try-Catch!! Javascript memperkenalkan pengendali tugasan selamat baharu✌. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!