If you code, it is certain that you use methods and functions no matter what programming language you are using. In javascript, since a lot of things works asyncronously, callbacks add a great feature to perform the post tasks. Let’s dive deep into it and understand what are they and how they work.
Let’s write a simple javascript function which returns a number
const getNumber = () => {
return 10
}
console.log(getNumber())
This code is self explanatory. A function getNumber() when called returns a number 10 and logs it in console.
[thejsway@jsmachine]$ node callback.js
10
Now, let’s do some changes to this function and make it asyncronous by adding a setTimeout() function. …