
Callback Functions – Callbacks are functions passed as arguments to be invoked after a task completes. They're commonly used for async code like network requests or timers.
๐ Syntax
function fetchData(callback) {
setTimeout(() => {
callback('Data received');
}, 1000);
}
๐งช Example
function fetchData(cb) {
setTimeout(() => cb('Done!'), 1000);
}
fetchData((data) => console.log(data));
Comments
Post a Comment