JS callbacks
JS callbacks

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. …

Tejaswi Kasat

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store