What is Callback

Callback
callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of action

Why we use
– we need to wait for a response from the server
– It helps us develop asynchronous JavaScript code and keeps us safe from problems and errors

The benefit of using a callback function is that you can wait for the result of a previous function call and then execute another function call.

function x (callBack){
   setTimeout(()=>{
      const p = "hello"
      callBack(p)
   },2000)
}
x(function(res){ console.log(res)})