Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Last active August 8, 2016 22:31
Show Gist options
  • Save peterbsmyth/432330294b18091c7e55b6caf8f5535f to your computer and use it in GitHub Desktop.
Save peterbsmyth/432330294b18091c7e55b6caf8f5535f to your computer and use it in GitHub Desktop.
function takesACallBack(something, callback) {
callback(something);
}
function logger(argument) {
console.log(argument);
}
logger("hello world");
takesACallBack("hello world", function(arg) {
console.log(arg);
});
// performsMath takes in a Number for a and b
// take a callback function for callback
// the callback functions arguments are two numbers
// Function to perform math on each passed in argument
// Invoked with arguments (firstNumber, secondNumber). Return result of mathematical function
function performsMath(a, b, callback) {
if(typeof callback !== 'function') {
throw Error("callback must be a function")
}
console.log(callback(a, b));
}
function add(first, second) {
return first + second;
}
function divide(first, second) {
return first / second;
}
function subtract(first, second) {
return first - second;
}
function multiply(first, second) {
return first * second;
}
performsMath(5,2, multiply);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment