What is a Callback? #devtools99 #callbacks #explained #webdevelopment #programming #coding
Your math teacher assigns you some homework, but being the mischievous student you are, you always prefer copying it from your friend rather than doing it yourself.
So, now you have two tasks:
1. do_homework: Completing your homework.
2. copy_homework: Copying the homework from your friend after they’ve finished theirs.
Now, even though your do_homework task is the priority, you don’t know how long it will take your friend to finish their homework. However, if you immediately try to execute copy_homework, you’ll end up copying incomplete work or nothing at all, which obviously won’t help.
This is where callbacks come into play. A callback is like a function that waits for another function to complete before being executed. In this scenario, it ensures that copy_homework only runs once do_homework (your friend’s homework) is finished.
By using a callback, you can make sure that copy_homework is only triggered after your friend completes their homework, preventing you from copying an empty or unfinished assignment.
DevTools99 is dedicated to assisting developers by providing valuable tips and tricks for development. Join us for insightful tutorials and tool recommendations by liking, sharing, and subscribing to DevTools99 on YouTube.
Stay connected with us on social media:
Facebook: / devtools99
Instagram: / devtools99
Twitter: / devtools99
Pinterest: / devtools99
@WebDevSimplified @lundeveloper @CodeWithHarry @BroCodez @programmingwithmosh
#javascript #html #website #devtools99 #developmenttips #developmenttricks