Javascript Callback with an example

function cal(cb){
/* you can write any operation that takes time here then send the result to callback as given bellow */

console.log(“After exact 1sec you will get hi message”)

setTimeout(function(){

cb(“hi”)
}, 1000)

}
}

cal(function(result){
console.log(result)
})