Explain Callback in Node.js?

A callback is a function that is called after another function has completed its execution. In JavaScript, functions are objects. Because of this , functions can take functions as arguments and can be returned by other functions. Any function that is passed as an argument is called a callback function.

JavaScript is an event driven language and runs code sequentially in top-down order. This means that instead for waiting for a response before moving on , JavaScript will keep executing while listening for other events. Callbacks make sure that a function is not going to run before a task is completed but will run right after the task has completed. It helps us develop asynchronous JavaScript code and keeps us safe from problems and errors.

const callback_function =()=>{

               console.log(“hello world”);

}

setTimeout(callback_function, 3000)