function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
// A function which accepts another function as an argument
// (and will automatically invoke that function when it completes - note that there is no explicit call to callbackFunction)
funct printANumber(int number, funct callbackFunction) {
printout("The number you provided is: " + number);
}
// a function which we will use in a driver function as a callback function
funct printFinishMessage() {
printout("I have finished printing numbers.");
}
// Driver method
funct event() {
printANumber(6, printFinishMessage);
}
//Callback functions - are functions that are called AFTER something happened
const foo = (number, callbackFunction) => {
//first
console.log(number)
//second - runs AFTER console.log() happened
callbackFunction()
}
// Create calculator calling different operators with functions in javascript
function pow(value0, value1) {
return Math.pow(value0, value1);
}
function mod(value0, value1) {
return value0 % value1;
}
function div(value0, value1) {
return value0 / value1;
}
function mul(value0, value1) {
return value0 * value1;
}
function add(value0, value1) {
return value0 + value1;
}
function subtract(value0, value1) {
return value0 - value1;
}
function calculator(value0, value1, operator) {
return operator(value0, value1);
}
console.log(calculator(2,5,mod));
function startWith(message, callback){
console.log("Clearly written messages is: " + message);
//check if the callback variable is a function..
if(typeof callback == "function"){
callback(); //execute function if function is truly a function.
}
}
//finally execute function at the end
startWith("This Messsage", function mySpecialCallback(){
console.log("Message from callback function");
})
const checkfile = (x,callback)=>{
if(typeof x !== 'number')
return callback('not a number'); //(err,{})
callback(false,'yes it is');
}
checkfile(4,(err, data)=>{
if(err)
console.log(err);
else
console.log(err);
})
const ironMan = withGloves(withBoots(withArmor(withHelmet(TonyStark))));
function greeting(name) {
alert(`Hello, ${name}`);
}
function processUserInput(callback) {
const name = prompt("Please enter your name.");
callback(name);
}
processUserInput(greeting);
// function
function greet(name) {
console.log('Hi' + ' ' + name);
}
greet('Peter'); // Hi Peter