Last active
May 10, 2021 15:21
-
-
Save pmogollons/da7fbb7f0f54928a46c378dff11dea5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function startCallbackHell() { | |
try { | |
const res1 = await callback1(params); | |
const res2 = await callback2(res1); | |
const res3 = await callback3(res2); | |
const res4 = await callback4(res3); | |
const res5 = await callback5(res4); | |
} catch (error) { | |
// Do something with the error | |
} finally { | |
// Do somthing after the try is executed, even if it gets an error | |
} | |
} | |
const callback1 = async (params) => { | |
// Actually do something | |
return 'res1'; | |
} | |
const callback2 = async (params) => { | |
// Actually do something | |
return 'res2'; | |
} | |
const callback3 = async (params) => { | |
// Actually do something | |
return 'res3'; | |
} | |
const callback4 = async (params) => { | |
// Actually do something | |
return 'res4'; | |
} | |
const callback5 = async (params) => { | |
// Actually do something | |
return 'res5'; | |
} |
Values are constant and are not updated later in the code, you should use let only when the value of the variable is going to be updated in upcoming code and try to never use var.
Values are constant and are not updated later in the code, you should use let only when the value of the variable is going to be updated in upcoming code and try to never use var.
Understandable :D Thanks :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you use const and not var or let ?