Asynchronous code involving callbacks

For asynchronous JavaScript APIs involving callbacks, you need to pass success and error callbacks, which will be called depending on whether the operation was a success or failure respectively. For example, while making an AJAX request using jQuery, we need to pass the callbacks, which will be executed depending on whether the AJAX request was made successfully or not. Consider this code snippet that makes an AJAX request using jQuery and logs the retrieved information:

function displayName(json) {    try {        console.log(json.Name);    } catch(e) {        console.log("Exception: " + e.message);    }}function displayProfession(json) {    try {        console.log(json.Profession);    } catch(e) { console.log("Exception: " + e.message); ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.