Function Callbacks in JavaScript
Learn how to use function callbacks by passing them as arguments to other functions.
We'll cover the following
Introduction to function callbacks
One of the most powerful features of JavaScript, and in fact, the technology that NodeJS was built on, is the concept of callback functions. A callback function is a function that is passed in as an argument to another function and is then generally invoked within the original function. In other words, we are calling a function and telling it to go and do what it needs to do, and when it is finished, to call the function that we have supplied.
Passing a function as an argument
Just as we can pass a value into a function, we can also pass a function into a function as one of its arguments.
This is best illustrated by taking a look at some JavaScript code as follows:
Get hands-on with 1200+ tech skills courses.