Skip to content

Day 4: Functions Calling Functions & Callbacks

Compose modular functions and understand higher-order functions that accept callbacks.

A callback is a function passed into another function as an argument:

function processTransaction(amount, callback) {
console.log(`Processing payment of $${amount}...`);
callback(amount);
}
const sendNotification = amt => {
console.log(`Receipt emailed for $${amt}`);
};
processTransaction(75, sendNotification);
  1. Write a calculate(a, b, operationCallback) function that accepts an operation function (add, subtract, etc.) and returns the result.