Quick actions

cmd+k|ctrl+k

Navigation

Languages

callback

Snippet info

Language

JavaScript

Visibility

public

Author

moin778866.ma

Created

2023-01-20T11:28:43.407557Z

Updated

2023-01-20T11:28:48.988516Z

// callback function
function total(sum, a, b){
    if(typeof(a) == 'number' && typeof(b) == 'number' ){
        return sum(a,b);
    }
}
// console.log(total(function(a,b){
//     return a+b
// }, 23, 12))

function sum(a,b){
    return a+b;
}

function multi(a,b){
    return a*b;
}

function calculate(callback, a, b){
    callback(a,b);
}

console.log(calculate(sum, 4,4));


// function when called say hello to the name
function greet(name){
    console.log('Hello ' + name);
}

function shout(name){
    console.log('Go away ' + name);
}

// function taking input and calling the greet function as a callback

function processUserInput(callback){
    const myName = 'Moin';
    callback(myName);
    
}

processUserInput(shout);
INFO