Functions as Arguments
A callback is a function that you pass as an argument to another function. The callback function is then executed at a later time, often after something completes.
Key Concept: Callbacks allow you to write flexible, reusable code by passing behavior (functions) as data.
function greet(name) { return `Hello, ${name}!`; } function processUser(name, callback) { // Call the callback function with the name let message = callback(name); console.log(message); } // Pass greet as a callback processUser('Alice', greet); // Outputs: Hello, Alice!