What are callback functions in JavaScript?

When a function is passed to another function, it is called a callback function. It goes over this function than to call a passed function.


You can try to run the following code to learn how to work with callback functions −

         var callback = function(myCallback) {
            setTimeout(function() {
            }, 5000);
         document.write("First is displayed");
         document.write("<br>Second is displayed");
         callback(function() {
             document.write("This is Callback function");
         document.write("<br>Last is displayed");