Callbacks in JavaScript
- A callback is a function passed as an argument to another function and is executed after the completion of a task.
function fetchData(callback) { setTimeout(() => { console.log('1. fetching data'); callback(); }, 5000);}
function processData() { console.log('2. processing data');}
fetchData(processData);/* After 5 sec =========== 1. fetching data 2. processing data*/