javascript what is callback code example
Example 1: javascript getposts callback
run.addEventListener('click', () => {
window.lib.getPosts((error, articles) => {
return (error ? console.log(error) : console.log(articles));
Example 2: callback function js
function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
Example 3: javascript callback
function newCallback(callback) {
callback('This can be any value you want to return')
}
function actionAferCallback (callbackData) {
console.log(callbackData)
}
function requestCallback() {
newCallback(actionAferCallback)
}