(function () {
'use strict';
function fetchData(callback) { // create the first (outer) function
const data = 'get data from an API';
setTimeout(() => {
callback(data); // use the callback param as a function and pass in the data value
}, 1000);
}
function displayData(data) { // create the inner function that takes in the callback as a param
console.log('processing data');
console.log(data);
}
fetchData(displayData); // finally call the outer function with the inner function as a value
})();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter