Callback function in JavaScript

 In JavaScript, a callback function is a function that is passed as an argument to another function and is executed after some operation is completed. Callback functions are widely used in asynchronous programming, such as when dealing with events, API calls, or timeouts.

here in this example we assigned the value from variable :: 

      function abc(val){
            console.log(val,"this is dummy text");
        }

        // var msg = "Hello!"
        abc("codetuts");

Why Use Callbacks?

  1. Control execution order: They allow asynchronous code to execute without blocking the main thread.
  2. Reusability: The same callback function can be reused in multiple contexts.
     function myFun(val){
                console.log(val(),"this is dummy text");
            }

            function cbfun(){
                console.log("i m callback function");
                // return 'called'
            }

            myFun(cbfun);